You are here

public function ManagedAd::getAdPlaceholder in Google AdSense integration 8

Return the ad placeholder.

Return value

array ad placeholder

Overrides AdsenseAdInterface::getAdPlaceholder

File

src/Plugin/AdsenseAd/ManagedAd.php, line 62

Class

ManagedAd
Provides an AdSense managed ad unit.

Namespace

Drupal\adsense\Plugin\AdsenseAd

Code

public function getAdPlaceholder() {
  if (!empty($this->format) && !empty($this->slot)) {
    $client = PublisherId::get();

    // Get width and height from the format.
    list($width, $height) = $this
      ->dimensions($this->format);
    $content = $this->configFactory
      ->get('adsense.settings')
      ->get('adsense_placeholder_text');
    $content .= "\nclient = ca-{$client}\nslot = {$this->slot}";
    if (ManagedAd::isResponsive($this->format) || ManagedAd::isFluid($this->format)) {
      $format = $this->format == 'responsive' ? implode(',', $this->shape) : $this->format;
      $content .= "\nformat = {$format}";
    }
    else {
      $content .= "\nwidth = {$width}\nheight = {$height}";
    }
    return [
      '#content' => [
        '#markup' => nl2br($content),
      ],
      '#format' => $this->format,
      '#width' => $width,
      '#height' => $height,
    ];
  }
  return [];
}