You are here

protected function TelephoneFormatter::viewLinkValue in Telephone Formatter 8

Generate the output appropriate for one field item.

Parameters

\Drupal\Core\Field\FieldItemInterface $item: One field value.

Return value

array The textual output generated as a render array.

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

File

src/Plugin/Field/FieldFormatter/TelephoneFormatter.php, line 216

Class

TelephoneFormatter
Plugin implementation of the 'telephone_formatter' formatter.

Namespace

Drupal\telephone_formatter\Plugin\Field\FieldFormatter

Code

protected function viewLinkValue(FieldItemInterface $item) {

  // Render each element as link.
  $element = [
    '#type' => 'link',
    '#title' => $this
      ->getFormattedValue($item),
    // Url prepended with 'tel:' schema.
    '#url' => Url::fromUri($this->formatter
      ->format($item->value, PhoneNumberFormat::RFC3966, $this
      ->getSetting('default_country'))),
    '#options' => [
      'external' => TRUE,
    ],
  ];
  if (!empty($item->_attributes)) {
    $element['#options'] += [
      'attributes' => [],
    ];
    $element['#options']['attributes'] += $item->_attributes;

    // Unset field item attributes since they have been included in the
    // formatter output and should not be rendered in the field template.
    unset($item->_attributes);
  }
  return $element;
}