1 | <?php |
||
26 | trait EntityHelperTrait { |
||
27 | |||
28 | /** |
||
29 | * The entity manager service. |
||
30 | * |
||
31 | * @var \Drupal\Core\Entity\EntityManagerInterface |
||
32 | */ |
||
33 | protected $entityManager; |
||
34 | |||
35 | /** |
||
36 | * The module handler service. |
||
37 | * |
||
38 | * @var \Drupal\Core\Extension\ModuleHandlerInterface. |
||
39 | */ |
||
40 | protected $moduleHandler; |
||
41 | |||
42 | /** |
||
43 | * The Entity Embed Display plugin manager. |
||
44 | * |
||
45 | * @var \Drupal\entity_embed\EntityEmbedDisplay\EntityEmbedDisplayManager. |
||
46 | */ |
||
47 | protected $displayPluginManager; |
||
48 | |||
49 | /** |
||
50 | * The renderer. |
||
51 | * |
||
52 | * @var \Drupal\Core\Render\RendererInterface. |
||
53 | */ |
||
54 | protected $renderer; |
||
55 | |||
56 | /** |
||
57 | * Loads an entity from the database. |
||
58 | * |
||
59 | * @param string $entity_type |
||
60 | * The entity type to load, e.g. node or user. |
||
61 | * @param mixed $id |
||
62 | * The id or UUID of the entity to load. |
||
63 | * |
||
64 | * @return \Drupal\Core\Entity\EntityInterface |
||
65 | * The entity object, or NULL if there is no entity with the given id or |
||
66 | * UUID. |
||
67 | */ |
||
68 | protected function loadEntity($entity_type, $id) { |
||
72 | |||
73 | /** |
||
74 | * Loads multiple entities from the database. |
||
75 | * |
||
76 | * @param string $entity_type |
||
77 | * The entity type to load, e.g. node or user. |
||
78 | * @param array $ids |
||
79 | * An array of entity IDs or UUIDs. |
||
80 | * |
||
81 | * @return array |
||
82 | * An array of entity objects indexed by their ids. |
||
83 | * |
||
84 | * @throws \Drupal\Core\Entity\EntityStorageException |
||
85 | * Throws an exception if the entity type does not supports UUIDs. |
||
86 | */ |
||
87 | protected function loadMultipleEntities($entity_type, array $ids) { |
||
106 | |||
107 | /** |
||
108 | * Determines if an entity can be rendered. |
||
109 | * |
||
110 | * @param \Drupal\Core\Entity\EntityInterface $entity |
||
111 | * The entity object. |
||
112 | * |
||
113 | * @return bool |
||
114 | * TRUE if the entity's type has a view builder controller, otherwise FALSE. |
||
115 | */ |
||
116 | protected function canRenderEntity(EntityInterface $entity) { |
||
120 | |||
121 | /** |
||
122 | * Determines if an entity type can be rendered. |
||
123 | * |
||
124 | * @param string $entity_type |
||
125 | * The entity type id. |
||
126 | * |
||
127 | * @return bool |
||
128 | * TRUE if the entitys type has a view builder controller, otherwise FALSE. |
||
129 | */ |
||
130 | protected function canRenderEntityType($entity_type) { |
||
133 | |||
134 | /** |
||
135 | * Returns the render array for an entity. |
||
136 | * |
||
137 | * @param \Drupal\Core\Entity\EntityInterface $entity |
||
138 | * The entity to be rendered. |
||
139 | * @param string $view_mode |
||
140 | * The view mode that should be used to display the entity. |
||
141 | * @param string $langcode |
||
142 | * (optional) For which language the entity should be rendered, defaults to |
||
143 | * the current content language. |
||
144 | * |
||
145 | * @return array |
||
146 | * A render array for the entity. |
||
147 | */ |
||
148 | protected function renderEntity(EntityInterface $entity, $view_mode, $langcode = NULL) { |
||
152 | |||
153 | /** |
||
154 | * Renders an embedded entity. |
||
155 | * |
||
156 | * @param \Drupal\Core\Entity\EntityInterface $entity |
||
157 | * The entity to be rendered. |
||
158 | * @param array $context |
||
159 | * (optional) Array of context values, corresponding to the attributes on |
||
160 | * the embed HTML tag. |
||
161 | * |
||
162 | * @return string |
||
163 | * The HTML of the entity rendered with the Entity Embed Display plugin. |
||
164 | */ |
||
165 | protected function renderEntityEmbed(EntityInterface $entity, array $context = array()) { |
||
227 | |||
228 | /** |
||
229 | * Renders an entity using an Entity Embed Display plugin. |
||
230 | * |
||
231 | * @param \Drupal\Core\Entity\EntityInterface $entity |
||
232 | * The entity to be rendered. |
||
233 | * @param string $plugin_id |
||
234 | * The Entity Embed Display plugin ID. |
||
235 | * @param array $plugin_configuration |
||
236 | * (optional) Array of plugin configuration values. |
||
237 | * @param array $context |
||
238 | * (optional) Array of additional context values, usually the embed HTML |
||
239 | * tag's attributes. |
||
240 | * |
||
241 | * @return array |
||
242 | * A render array for the Entity Embed Display plugin. |
||
243 | */ |
||
244 | protected function renderEntityEmbedDisplayPlugin(EntityInterface $entity, $plugin_id, array $plugin_configuration = array(), array $context = array()) { |
||
259 | |||
260 | /** |
||
261 | * Returns the entity manager. |
||
262 | * |
||
263 | * @return \Drupal\Core\Entity\EntityManagerInterface |
||
264 | * The entity manager. |
||
265 | */ |
||
266 | protected function entityManager() { |
||
272 | |||
273 | /** |
||
274 | * Sets the entity manager service. |
||
275 | * |
||
276 | * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager |
||
277 | * The entity manager service. |
||
278 | * |
||
279 | * @return self |
||
280 | */ |
||
281 | public function setEntityManager(EntityManagerInterface $entity_manager) { |
||
285 | |||
286 | /** |
||
287 | * Returns the module handler. |
||
288 | * |
||
289 | * @return \Drupal\Core\Extension\ModuleHandlerInterface |
||
290 | * The module handler. |
||
291 | */ |
||
292 | protected function moduleHandler() { |
||
298 | |||
299 | /** |
||
300 | * Sets the module handler service. |
||
301 | * |
||
302 | * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler |
||
303 | * The module handler service. |
||
304 | * |
||
305 | * @return self |
||
306 | */ |
||
307 | public function setModuleHandler(ModuleHandlerInterface $module_handler) { |
||
311 | |||
312 | /** |
||
313 | * Returns the Entity Embed Display plugin manager. |
||
314 | * |
||
315 | * @return \Drupal\entity_embed\EntityEmbedDisplay\EntityEmbedDisplayManager |
||
316 | * The Entity Embed Display plugin manager. |
||
317 | */ |
||
318 | protected function displayPluginManager() { |
||
324 | |||
325 | /** |
||
326 | * Sets the Entity Embed Display plugin manager service. |
||
327 | * |
||
328 | * @param \Drupal\entity_embed\EntityEmbedDisplay\EntityEmbedDisplayManager $display_plugin_manager |
||
329 | * The Entity Embed Display plugin manager service. |
||
330 | * |
||
331 | * @return self |
||
332 | */ |
||
333 | public function setDisplayPluginManager(EntityEmbedDisplayManager $display_plugin_manager) { |
||
337 | |||
338 | /** |
||
339 | * Returns the renderer. |
||
340 | * |
||
341 | * @return \Drupal\Core\Render\RendererInterface |
||
342 | * The renderer. |
||
343 | */ |
||
344 | protected function renderer() { |
||
350 | |||
351 | /** |
||
352 | * Sets the renderer. |
||
353 | * |
||
354 | * @param \Drupal\Core\Render\RendererInterface $renderer |
||
355 | * The renderer. |
||
356 | * |
||
357 | * @return self |
||
358 | */ |
||
359 | public function setRenderer(RendererInterface $renderer) { |
||
363 | } |
||
364 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..