You are here

protected function TwitterEmbedFormatter::getEmbedCode in Media entity Twitter 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/Field/FieldFormatter/TwitterEmbedFormatter.php \Drupal\media_entity_twitter\Plugin\Field\FieldFormatter\TwitterEmbedFormatter::getEmbedCode()

Extracts the embed code from a field item.

Parameters

\Drupal\Core\Field\FieldItemInterface $item: The field item.

Return value

string|null The embed code, or NULL if the field type is not supported.

1 call to TwitterEmbedFormatter::getEmbedCode()
TwitterEmbedFormatter::viewElements in src/Plugin/Field/FieldFormatter/TwitterEmbedFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/TwitterEmbedFormatter.php, line 74

Class

TwitterEmbedFormatter
Plugin implementation of the 'twitter_embed' formatter.

Namespace

Drupal\media_entity_twitter\Plugin\Field\FieldFormatter

Code

protected function getEmbedCode(FieldItemInterface $item) {
  switch ($item
    ->getFieldDefinition()
    ->getType()) {
    case 'link':
      return $item->uri;
    case 'string':
    case 'string_long':
      return $item->value;
    default:
      break;
  }
}