Builds a renderable array for a field value.
Drupal\Core\Entity\EntityInterface $entity: The entity being displayed.
string $langcode: The language associated with $items.
array $items: Array of values for this field.
array A renderable array for $items, as an array of child elements keyed by numeric indexes starting from 0.
Overrides FormatterInterface::viewElements
public function viewElements(EntityInterface $entity, $langcode, array $items) {
$element = array();
foreach ($items as $delta => $item) {
// Prepend 'tel:' to the telephone number.
$href = 'tel:' . rawurlencode(preg_replace('/\\s+/', '', $item['value']));
// Render each element as link.
$element[$delta] = array(
'#type' => 'link',
'#title' => $item['title'],
'#href' => $href,
'#options' => array(
'external' => TRUE,
),
);
}
return $element;
}