Pull merge.
[yaffs-website] / web / core / lib / Drupal / Core / Field / Plugin / Field / FieldFormatter / MailToFormatter.php
1 <?php
2
3 namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
4
5 use Drupal\Core\Field\FormatterBase;
6 use Drupal\Core\Field\FieldItemListInterface;
7 use Drupal\Core\Url;
8
9 /**
10  * Plugin implementation of the 'email_mailto' formatter.
11  *
12  * @FieldFormatter(
13  *   id = "email_mailto",
14  *   label = @Translation("Email"),
15  *   field_types = {
16  *     "email"
17  *   }
18  * )
19  */
20 class MailToFormatter extends FormatterBase {
21
22   /**
23    * {@inheritdoc}
24    */
25   public function viewElements(FieldItemListInterface $items, $langcode) {
26     $elements = [];
27
28     foreach ($items as $delta => $item) {
29       $elements[$delta] = [
30         '#type' => 'link',
31         '#title' => $item->value,
32         '#url' => Url::fromUri('mailto:' . $item->value),
33       ];
34     }
35
36     return $elements;
37   }
38
39 }