public function YamlFormEntityReferenceEntityFormatter::viewElements in YAML Form 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/ YamlFormEntityReferenceEntityFormatter.php, line 78
Class
- YamlFormEntityReferenceEntityFormatter
- Plugin implementation of the 'Form rendered entity' formatter.
Namespace
Drupal\yamlform\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$source_entity = $items
->getEntity();
$this->messageManager
->setSourceEntity($source_entity);
$elements = [];
foreach ($this
->getEntitiesToView($items, $langcode) as $delta => $entity) {
/** @var \Drupal\yamlform\YamlFormInterface $entity */
// Do not display the form if the current user can't create submissions.
if ($entity
->id() && !$entity
->access('submission_create')) {
continue;
}
if ($entity
->id() && $items[$delta]->status) {
$elements[$delta] = $entity
->getSubmissionForm();
}
else {
$this->messageManager
->setYamlForm($entity);
$elements[$delta] = $this->messageManager
->build(YamlFormMessageManagerInterface::FORM_CLOSED_MESSAGE);
}
}
return $elements;
}