diff --git a/core/lib/Drupal/Core/Entity/DisplayComponentHandlerBase.php b/core/lib/Drupal/Core/Entity/DisplayComponentHandlerBase.php index a31d9e6..4e72b10 100644 --- a/core/lib/Drupal/Core/Entity/DisplayComponentHandlerBase.php +++ b/core/lib/Drupal/Core/Entity/DisplayComponentHandlerBase.php @@ -61,4 +61,10 @@ public function massageOut($properties) { public function getRenderer($name, array $options) { } + /** + * {@inheritdoc} + */ + public function buildMultiple(array $entities, &$build_list, $content) { + } + } diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php index 1ab3651..32cd306 100644 --- a/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php +++ b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php @@ -183,26 +183,10 @@ public function buildMultiple(array $entities) { $build_list[$key] = array(); } - // Run field formatters. - foreach ($this->getFieldDefinitions() as $field_name => $definition) { - if ($formatter = $this->getRenderer($field_name)) { - // Group items across all entities and pass them to the formatter's - // prepareView() method. - $grouped_items = array(); - foreach ($entities as $id => $entity) { - $items = $entity->get($field_name); - $items->filterEmptyItems(); - $grouped_items[$id] = $items; - } - $formatter->prepareView($grouped_items); - - // Then let the formatter build the output for each entity. - foreach ($entities as $key => $entity) { - $items = $entity->get($field_name); - $build_list[$key][$field_name] = $formatter->view($items); - $build_list[$key][$field_name]['#access'] = $items->access('view'); - } - } + // Let the component handlers add missing components. + $handlers = $this->handlerManager->getDefinitions(); + foreach (array_keys($handlers) as $type) { + $this->getComponentHandler($type)->buildMultiple($entities, $build_list, $this->content); } foreach ($entities as $key => $entity) { diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php index a5bc902..ba24927 100644 --- a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php @@ -335,45 +335,6 @@ public function getHighestWeight() { } /** - * Returns the field definition of a field. - */ - protected function getFieldDefinition($field_name) { - $definitions = $this->getFieldDefinitions(); - return isset($definitions[$field_name]) ? $definitions[$field_name] : NULL; - } - - /** - * Returns the definitions of the fields that are candidate for display. - */ - protected function getFieldDefinitions() { - // Entity displays are sometimes created for non-content entities. - // @todo Prevent this in https://drupal.org/node/2095195. - if (!\Drupal::entityManager()->getDefinition($this->targetEntityType)->isSubclassOf('\Drupal\Core\Entity\FieldableEntityInterface')) { - return array(); - } - - if (!isset($this->fieldDefinitions)) { - $definitions = \Drupal::entityManager()->getFieldDefinitions($this->targetEntityType, $this->bundle); - $this->fieldDefinitions = array_filter($definitions, array($this, 'fieldHasDisplayOptions')); - } - - return $this->fieldDefinitions; - } - - /** - * Determines if a field has options for a given display. - * - * @param FieldDefinitionInterface $definition - * A field definition. - * @return array|null - */ - private function fieldHasDisplayOptions(FieldDefinitionInterface $definition) { - // The display only cares about fields that specify display options. - // Discard base fields that are not rendered through formatters / widgets. - return $definition->getDisplayOptions($this->displayContext); - } - - /** * {@inheritdoc} */ public function onDependencyRemoval(array $dependencies) { diff --git a/core/lib/Drupal/Core/Entity/Plugin/DisplayComponent/FieldDisplayComponentHandler.php b/core/lib/Drupal/Core/Entity/Plugin/DisplayComponent/FieldDisplayComponentHandler.php index 0b51039..3fd5d2f 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/DisplayComponent/FieldDisplayComponentHandler.php +++ b/core/lib/Drupal/Core/Entity/Plugin/DisplayComponent/FieldDisplayComponentHandler.php @@ -200,4 +200,32 @@ protected function getFieldDefinitions() { }); } + /** + * {@inheritdoc} + */ + public function buildMultiple(array $entities, &$build_list, $content) { + // Run field formatters. + foreach ($this->getFieldDefinitions() as $field_name => $definition) { + $options = isset($content[$field_name]) ? $content[$field_name] : array(); + if ($formatter = $this->getRenderer($field_name, $options)) { + // Group items across all entities and pass them to the formatter's + // prepareView() method. + $grouped_items = array(); + foreach ($entities as $id => $entity) { + $items = $entity->get($field_name); + $items->filterEmptyItems(); + $grouped_items[$id] = $items; + } + $formatter->prepareView($grouped_items); + + // Then let the formatter build the output for each entity. + foreach ($entities as $key => $entity) { + $items = $entity->get($field_name); + $build_list[$key][$field_name] = $formatter->view($items); + $build_list[$key][$field_name]['#access'] = $items->access('view'); + } + } + } + } + }