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