You are here

public function FacebookEmbedFormatter::viewElements in Media entity facebook 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldFormatter/FacebookEmbedFormatter.php \Drupal\media_entity_facebook\Plugin\Field\FieldFormatter\FacebookEmbedFormatter::viewElements()
  2. 3.x src/Plugin/Field/FieldFormatter/FacebookEmbedFormatter.php \Drupal\media_entity_facebook\Plugin\Field\FieldFormatter\FacebookEmbedFormatter::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

File

src/Plugin/Field/FieldFormatter/FacebookEmbedFormatter.php, line 27

Class

FacebookEmbedFormatter
Plugin implementation of the 'facebook_embed' formatter.

Namespace

Drupal\media_entity_facebook\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {

  /** @var \Drupal\media_entity\MediaInterface $media_entity */
  $media_entity = $items
    ->getEntity();
  $element = [];
  if (($type = $media_entity
    ->getType()) && $type instanceof Facebook) {
    foreach ($items as $delta => $item) {
      $element[$delta] = [
        '#markup' => FacebookMarkup::create($type
          ->getField($media_entity, 'html')),
      ];
    }
  }
  return $element;
}