You are here

public function IframeDefaultFormatter::viewElements in Iframe 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/Field/FieldFormatter/IframeDefaultFormatter.php \Drupal\iframe\Plugin\Field\FieldFormatter\IframeDefaultFormatter::viewElements()

Builds a renderable array for a field value.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.

string $langcode: The language that should be used to render the field.

Return value

array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.

Overrides FormatterInterface::viewElements

3 methods override IframeDefaultFormatter::viewElements()
IframeAsurlFormatter::viewElements in src/Plugin/Field/FieldFormatter/IframeAsurlFormatter.php
Builds a renderable array for a field value.
IframeAsurlwithuriFormatter::viewElements in src/Plugin/Field/FieldFormatter/IframeAsurlwithuriFormatter.php
Builds a renderable array for a field value.
IframeOnlyFormatter::viewElements in src/Plugin/Field/FieldFormatter/IframeOnlyFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/IframeDefaultFormatter.php, line 44

Class

IframeDefaultFormatter
Class IframeDefaultFormatter.

Namespace

Drupal\iframe\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $elements = [];
  $field_settings = $this
    ->getFieldSettings();
  $settings = $this
    ->getSettings();
  $entity = $items
    ->getEntity();
  \iframe_debug(3, __METHOD__, $field_settings);
  \iframe_debug(3, __METHOD__, $settings);
  \iframe_debug(3, __METHOD__, $entity);

  // \iframe_debug(3, __METHOD__, $items->getValue());
  foreach ($items as $delta => $item) {
    if (empty($item->url)) {
      continue;
    }
    if (!(property_exists($item, 'title') && $item->title !== null)) {
      $item->title = '';
    }
    $elements[$delta] = self::iframeIframe($item->title, $item->url, $item);

    // Tokens can be dynamic, so its not cacheable.
    if (isset($settings['tokensupport']) && $settings['tokensupport']) {
      $elements[$delta]['cache'] = [
        'max-age' => 0,
      ];
    }
  }
  return $elements;
}