private function DrupalInstantArticleDisplay::fieldFormatTransfomer in Facebook Instant Articles 7
Formatter for any markup field that must needs be piped through the Transfomer object.
Parameters
$items:
InstantArticle $body:
$instance:
$langcode:
1 call to DrupalInstantArticleDisplay::fieldFormatTransfomer()
- DrupalInstantArticleDisplay::fieldFormatterView in modules/
fb_instant_articles_display/ src/ DrupalInstantArticleDisplay.php
File
- modules/
fb_instant_articles_display/ src/ DrupalInstantArticleDisplay.php, line 474 - 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_displayCode
private function fieldFormatTransfomer($items, $body, $instance, $langcode) {
$transformer = new Transformer();
$transformer
->loadRules(file_get_contents(__DIR__ . '/../transformer_config.json'));
drupal_alter('fb_instant_articles_display_transformer', $transformer);
foreach ($items as $delta => $item) {
// @see _text_sanitize().
if (isset($item['safe_value'])) {
$output = $item['safe_value'];
}
else {
$output = $instance['settings']['text_processing'] ? check_markup($item['value'], $item['format'], $langcode) : check_plain($item['value']);
}
// Pass the markup through Transformer::transform().
$document = new \DOMDocument();
// Before loading into DOMDocument, setup for success by taking care of
// encoding issues. Since we're dealing with HTML snippets, it will
// always be missing a <meta charset="utf-8" /> or equivalent.
$output = '<!doctype html><html><head><meta charset="utf-8" /></head><body>' . $output . '</body></html>';
@$document
->loadHTML(decode_entities($output));
$transformer
->transform($body, $document);
// @todo store entity warnings so we can display them in the admin
}
}