3 namespace Drupal\Core\Entity;
5 use Drupal\Core\Field\FieldItemInterface;
6 use Drupal\Core\Field\FieldItemListInterface;
9 * Defines an interface for entity view builders.
13 interface EntityViewBuilderInterface {
16 * Builds the component fields and properties of a set of entities.
19 * The renderable array representing the entity content.
20 * @param \Drupal\Core\Entity\EntityInterface[] $entities
21 * The entities whose content is being built.
22 * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface[] $displays
23 * The array of entity view displays holding the display options
24 * configured for the entity components, keyed by bundle name.
25 * @param string $view_mode
26 * The view mode in which the entity is being viewed.
28 public function buildComponents(array &$build, array $entities, array $displays, $view_mode);
31 * Builds the render array for the provided entity.
33 * @param \Drupal\Core\Entity\EntityInterface $entity
34 * The entity to render.
35 * @param string $view_mode
36 * (optional) The view mode that should be used to render the entity.
37 * @param string $langcode
38 * (optional) For which language the entity should be rendered, defaults to
39 * the current content language.
42 * A render array for the entity.
44 * @throws \InvalidArgumentException
45 * Can be thrown when the set of parameters is inconsistent, like when
46 * trying to view a Comment and passing a Node which is not the one the
47 * comment belongs to, or not passing one, and having the comment node not
48 * be available for loading.
50 public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL);
53 * Builds the render array for the provided entities.
55 * @param array $entities
56 * An array of entities implementing EntityInterface to view.
57 * @param string $view_mode
58 * (optional) The view mode that should be used to render the entity.
59 * @param string $langcode
60 * (optional) For which language the entity should be rendered, defaults to
61 * the current content language.
64 * A render array for the entities, indexed by the same keys as the
65 * entities array passed in $entities.
67 * @throws \InvalidArgumentException
68 * Can be thrown when the set of parameters is inconsistent, like when
69 * trying to view Comments and passing a Node which is not the one the
70 * comments belongs to, or not passing one, and having the comments node not
71 * be available for loading.
73 public function viewMultiple(array $entities = [], $view_mode = 'full', $langcode = NULL);
76 * Resets the entity render cache.
78 * @param \Drupal\Core\Entity\EntityInterface[] $entities
79 * (optional) If specified, the cache is reset for the given entities only.
81 public function resetCache(array $entities = NULL);
84 * Builds a renderable array for the value of a single field in an entity.
86 * The resulting output is a fully themed field with label and multiple
89 * This function can be used by third-party modules that need to output an
91 * - Do not use inside node (or any other entity) templates; use
92 * render($content[FIELD_NAME]) instead.
93 * - The FieldItemInterface::view() method can be used to output a single
94 * formatted field value, without label or wrapping field markup.
96 * The function takes care of invoking the prepare_view steps. It also
97 * respects field access permissions.
99 * @param \Drupal\Core\Field\FieldItemListInterface $items
100 * FieldItemList containing the values to be displayed.
101 * @param string|array $display_options
103 * - The name of a view mode. The field will be displayed according to the
104 * display settings specified for this view mode in the $field
105 * definition for the field in the entity's bundle. If no display settings
106 * are found for the view mode, the settings for the 'default' view mode
108 * - An array of display options. The following key/value pairs are allowed:
109 * - label: (string) Position of the label. The default 'field' theme
110 * implementation supports the values 'inline', 'above' and 'hidden'.
111 * Defaults to 'above'.
112 * - type: (string) The formatter to use. Defaults to the
113 * 'default_formatter' for the field type. The default formatter will
114 * also be used if the requested formatter is not available.
115 * - settings: (array) Settings specific to the formatter. Defaults to the
116 * formatter's default settings.
117 * - weight: (float) The weight to assign to the renderable element.
121 * A renderable array for the field values.
123 * @see \Drupal\Core\Entity\EntityViewBuilderInterface::viewFieldItem()
125 public function viewField(FieldItemListInterface $items, $display_options = []);
128 * Builds a renderable array for a single field item.
130 * @param \Drupal\Core\Field\FieldItemInterface $item
131 * FieldItem to be displayed.
132 * @param string|array $display_options
133 * Can be either the name of a view mode, or an array of display settings.
134 * See EntityViewBuilderInterface::viewField() for more information.
137 * A renderable array for the field item.
139 * @see \Drupal\Core\Entity\EntityViewBuilderInterface::viewField()
141 public function viewFieldItem(FieldItemInterface $item, $display_options = []);
144 * The cache tag associated with this entity view builder.
146 * An entity view builder is instantiated on a per-entity type basis, so the
147 * cache tags are also per-entity type.
150 * An array of cache tags.
152 public function getCacheTags();