diff --git a/core/modules/field/lib/Drupal/field/Plugin/DisplayComponent/FieldDisplayComponentHandler.php b/core/modules/field/lib/Drupal/field/Plugin/DisplayComponent/FieldDisplayComponentHandler.php index b56f459..8bc9c5a 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/DisplayComponent/FieldDisplayComponentHandler.php +++ b/core/modules/field/lib/Drupal/field/Plugin/DisplayComponent/FieldDisplayComponentHandler.php @@ -196,26 +196,23 @@ protected function getFieldDefinition($field_name) { * Returns the definitions of the fields that are candidate for display. */ protected function getFieldDefinitions() { - // @todo Replace this with \Drupal::entityManager()->getFieldDefinition() - // when it can hand the $instance objects (and then reconsider the - // $this->fieldDefinitions static cache ?) - // https://drupal.org/node/2114707 $entity_manager = \Drupal::entityManager(); - $entity_info = $entity_manager->getDefinition($this->context['entity_type']); - $definitions = array(); - if ($entity_info->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface')) { - $entity = _field_create_entity_from_ids((object) array('entity_type' => $this->context['entity_type'], 'bundle' => $this->context['bundle'], 'entity_id' => NULL)); - foreach ($entity as $field_name => $items) { - $definitions[$field_name] = $items->getFieldDefinition(); - } + // Entity displays are sometimes created for non-content entities. + // @todo Prevent this in https://drupal.org/node/2095195. + if (!$entity_manager->getDefinition($this->context['entity_type'])->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface')) { + return array(); } - // The display only cares about fields that specify display options. - // Discard base fields that are not rendered through formatters / widgets. - $display_context = $this->context['display_context']; - $this->fieldDefinitions = array_filter($definitions, function (FieldDefinitionInterface $definition) use ($display_context) { - return $definition->getDisplayOptions($display_context); - }); + if (!isset($this->fieldDefinitions)) { + $definitions = $entity_manager->getFieldDefinitions($this->context['entity_type'], $this->context['bundle']); + + // The display only cares about fields that specify display options. + // Discard base fields that are not rendered through formatters / widgets. + $display_context = $this->context['display_context']; + $this->fieldDefinitions = array_filter($definitions, function (FieldDefinitionInterface $definition) use ($display_context) { + return $definition->getDisplayOptions($display_context); + }); + } return $this->fieldDefinitions; }