public EntityViewBuilder::viewField(FieldItemListInterface $items, $display_options = array())
Builds a renderable array for the value of a single field in an entity.
The resulting output is a fully themed field with label and multiple values.
This function can be used by third-party modules that need to output an isolated field.
The function takes care of invoking the prepare_view steps. It also respects field access permissions.
\Drupal\Core\Field\FieldItemListInterface $items: FieldItemList containing the values to be displayed.
string|array $display_options: Can be either:
array A renderable array for the field values.
Overrides EntityViewBuilderInterface::viewField
\Drupal\Core\Entity\EntityViewBuilderInterface::viewFieldItem()
public function viewField(FieldItemListInterface $items, $display_options = array()) { $entity = $items->getEntity(); $field_name = $items->getFieldDefinition()->getName(); $display = $this->getSingleFieldDisplay($entity, $field_name, $display_options); $output = array(); $build = $display->build($entity); if (isset($build[$field_name])) { $output = $build[$field_name]; } return $output; }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!EntityViewBuilder.php/function/EntityViewBuilder::viewField/8.1.x