You are here

private function DrupalInstantArticleDisplay::fieldFormatAdElement in Facebook Instant Articles 7

Formatter for the Ad element.

Parameters

$items:

Header $header:

$settings:

1 call to DrupalInstantArticleDisplay::fieldFormatAdElement()
DrupalInstantArticleDisplay::fieldFormatterView in modules/fb_instant_articles_display/src/DrupalInstantArticleDisplay.php

File

modules/fb_instant_articles_display/src/DrupalInstantArticleDisplay.php, line 370
Contains \Drupal\fb_instant_articles_display\DrupalInstantArticleDisplay.

Class

DrupalInstantArticleDisplay
Facebook Instant Article node wrapper class. Builds up an InstantArticle object using field formatters.

Namespace

Drupal\fb_instant_articles_display

Code

private function fieldFormatAdElement($items, $header, $settings) {
  foreach ($items as $delta => $item) {
    $ad = Ad::create();
    if (!empty($settings['height'])) {
      $ad
        ->withHeight($settings['height']);
    }
    if (!empty($settings['width'])) {
      $ad
        ->withWidth($settings['width']);
    }
    if ($settings['source'] === 'embed') {

      // @todo sanitize text before sending off to FB IA SDK?
      $ad
        ->withHtml($item['value']);
    }
    else {

      // @todo sanitize text before sending off to FB IA SDK?
      $ad
        ->withSource($item['value']);
    }
    $header
      ->addAd($ad);
  }
}