You are here

public function SocialLinkBaseFormatter::viewElements in Social Link Field 8

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

2 calls to SocialLinkBaseFormatter::viewElements()
SocialLinkFontAwesomeFormatter::viewElements in src/Plugin/Field/FieldFormatter/SocialLinkFontAwesomeFormatter.php
Builds a renderable array for a field value.
SocialLinkNetworkNameFormatter::viewElements in src/Plugin/Field/FieldFormatter/SocialLinkNetworkNameFormatter.php
Builds a renderable array for a field value.
2 methods override SocialLinkBaseFormatter::viewElements()
SocialLinkFontAwesomeFormatter::viewElements in src/Plugin/Field/FieldFormatter/SocialLinkFontAwesomeFormatter.php
Builds a renderable array for a field value.
SocialLinkNetworkNameFormatter::viewElements in src/Plugin/Field/FieldFormatter/SocialLinkNetworkNameFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/SocialLinkBaseFormatter.php, line 82

Class

SocialLinkBaseFormatter
Base class for 'Field formatter' plugin implementations.

Namespace

Drupal\social_link_field\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $entity = $items
    ->getParent()
    ->getValue();
  $element = [
    '#theme' => 'social_link_field_formatter',
    '#new_tab' => $this
      ->getSetting('new_tab'),
    '#attributes' => [
      'data-quickedit-field-id' => implode('/', [
        $entity
          ->getEntityTypeId(),
        $entity
          ->id(),
        $items
          ->getName(),
        $langcode,
        $this->viewMode,
      ]),
    ],
  ];
  return $element;
}