You are here

public function SocialLinkNetworkNameFormatter::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 SocialLinkBaseFormatter::viewElements

File

src/Plugin/Field/FieldFormatter/SocialLinkNetworkNameFormatter.php, line 52

Class

SocialLinkNetworkNameFormatter
Plugin implementation of the 'social_link_field' formatter.

Namespace

Drupal\social_link_field\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $element = parent::viewElements($items, $langcode);
  $element['#appearance'] = [
    'orientation' => $this
      ->getSetting('orientation'),
  ];
  foreach ($items as $delta => $item) {
    $values = $item
      ->getValue();
    $social = $values['social'];
    $link = $values['link'];
    $element['#links'][$delta] = [
      'text' => $this->platforms[$social]['name'],
      'class' => $social,
      'url' => $this->platforms[$social]['urlPrefix'] . $link,
      'title' => $this->platforms[$social]['name'],
    ];
  }
  return $element;
}