You are here

private function DrupalInstantArticleDisplay::fieldFormatAnalyticsElement in Facebook Instant Articles 7

Formatter for the Analytics element.

Parameters

$items:

InstantArticle $body:

$settings:

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

File

modules/fb_instant_articles_display/src/DrupalInstantArticleDisplay.php, line 398
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 fieldFormatAnalyticsElement($items, $body, $settings) {
  foreach ($items as $delta => $item) {
    $analytics = Analytics::create();
    if ($settings['source'] === 'embed') {

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

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