public function EmailContactInlineFormatter::viewElements in Email Contact 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
File
- src/
Plugin/ Field/ FieldFormatter/ EmailContactInlineFormatter.php, line 112
Class
- EmailContactInlineFormatter
- Plugin implementation of the 'email_contact_inline' formatter.
Namespace
Drupal\email_contact\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = array();
foreach ($items as $delta => $item) {
/** @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = $item
->getEntity();
try {
$form = new ContactForm($entity
->getEntityTypeId(), $entity
->id(), $items
->getName(), $this
->getSettings());
$elements[$delta]['form'] = \Drupal::formBuilder()
->getForm($form);
} catch (NotFoundHttpException $e) {
\Drupal::logger('email_contact')
->notice('Invalid inline contact form on @entity_type id @id.', [
'@entity_type' => $entity
->getEntityTypeId(),
'@id' => $entity
->id(),
]);
}
break;
}
return $elements;
}