You are here

public function OldCodeAd::getAdContent in Google AdSense integration 8

Return the ad content.

Return value

array ad content

Overrides AdsenseAdInterface::getAdContent

File

oldcode/src/Plugin/AdsenseAd/OldCodeAd.php, line 80

Class

OldCodeAd
Provides an AdSense old code ad unit.

Namespace

Drupal\adsense_oldcode\Plugin\AdsenseAd

Code

public function getAdContent() {
  if (!empty($this->format)) {
    $ad = $this
      ->adsenseAdFormats($this->format);
    if ($ad != NULL) {
      $core_config = $this->configFactory
        ->get('adsense.settings');
      $oldcode_config = $this->configFactory
        ->get('adsense_oldcode.settings');
      $client = PublisherId::get();
      $this->moduleHandler
        ->alter('adsense', $client);

      // Get width and height from the format.
      list($width, $height) = $this
        ->dimensions($this->format);
      switch ($oldcode_config
        ->get('adsense_ad_type_' . $this->style)) {
        case 0:
          $type = 'text';
          break;
        case 1:
          $type = 'image';
          break;
        default:
          $type = 'text_image';
          break;
      }
      $alt = $oldcode_config
        ->get('adsense_alt_' . $this->style);
      $alt_info = $oldcode_config
        ->get('adsense_alt_info_' . $this->style);
      return [
        '#theme' => 'adsense_oldcode',
        '#client' => $client,
        '#alt_url' => $alt == 1 ? $alt_info : '',
        '#alt_color' => $alt == 2 ? $alt_info : '',
        '#width' => $width,
        '#height' => $height,
        '#format' => $ad['code'],
        '#type' => $ad['type'] == ADSENSE_OLDCODE_TYPE_AD ? $type : '',
        '#channel' => $oldcode_config
          ->get('adsense_ad_channel_' . $this->channel),
        '#border' => mb_substr($oldcode_config
          ->get('adsense_color_border_' . $this->style), 1),
        '#bg' => mb_substr($oldcode_config
          ->get('adsense_color_bg_' . $this->style), 1),
        '#link' => mb_substr($oldcode_config
          ->get('adsense_color_link_' . $this->style), 1),
        '#text' => mb_substr($oldcode_config
          ->get('adsense_color_text_' . $this->style), 1),
        '#url' => mb_substr($oldcode_config
          ->get('adsense_color_url_' . $this->style), 1),
        '#features' => $oldcode_config
          ->get('adsense_ui_features_' . $this->style),
        '#secret' => $core_config
          ->get('adsense_secret_language'),
      ];
    }
  }
  return [];
}