diff -u b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php --- b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php +++ b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php @@ -45,16 +45,6 @@ public $bundle; /** - * A partial entity, created via _field_create_entity_from_ids() from - * $targetEntityType and $bundle. - * - * @var \Drupal\Core\Entity\EntityInterface - * - * @todo Remove when getFieldDefinition() is fixed to not need it. - */ - private $targetEntity; - - /** * View or form mode to be displayed. * * @var string @@ -303,15 +293,17 @@ /** * Returns the field definition of a field. + * + * @param string $name + * The name of the component. + * + * @return \Drupal\Core\Field\FieldDefinitionInterface|NULL + * The field definition if the component is a field. */ - protected function getFieldDefinition($field_name) { - // @todo Replace this entire implementation with - // \Drupal::entityManager()->getFieldDefinition() after [#2047229] lands. - if (!isset($this->targetEntity)) { - $this->targetEntity = _field_create_entity_from_ids((object) array('entity_type' => $this->targetEntityType, 'bundle' => $this->bundle, 'entity_id' => NULL)); - } - if (($this->targetEntity instanceof ContentEntityInterface) && $this->targetEntity->hasField($field_name)) { - return $this->targetEntity->get($field_name)->getFieldDefinition(); + protected function getFieldDefinition($name) { + $field_definitions = \Drupal::entityManager()->getFieldDefinitions($this->targetEntityType, $this->bundle); + if (isset($field_definitions[$name])) { + return $field_definitions[$name]; } } } diff -u b/core/modules/field/field.attach.inc b/core/modules/field/field.attach.inc --- b/core/modules/field/field.attach.inc +++ b/core/modules/field/field.attach.inc @@ -220,28 +220,16 @@ * @param $options * An associative array of options, as provided to field_invoke_method(). Only * the following keys are considered: - * - deleted * - field_name - * - field_id * See field_invoke_method() for details. * - * @return + * @return \Drupal\Core\Field\FieldDefinitionInterface[] * The array of selected field definitions. */ function _field_invoke_get_field_definitions($entity_type, $bundle, $options) { - // @todo Replace with \Drupal::entityManager()->getFieldDefinition() after - // [#2047229] lands. - $entity = _field_create_entity_from_ids((object) array('entity_type' => $entity_type, 'bundle' => $bundle, 'entity_id' => NULL)); - $field_definitions = array(); + $field_definitions = \Drupal::entityManager()->getFieldDefinitions($entity_type, $bundle); if (isset($options['field_name'])) { - if ($entity->hasField($options['field_name'])) { - $field_definitions[] = $entity->get($options['field_name'])->getFieldDefinition(); - } - } - else { - foreach ($entity as $items) { - $field_definitions[] = $items->getFieldDefinition(); - } + $field_definitions = array_intersect_key($field_definitions, array($options['field_name'] => TRUE)); } return $field_definitions; diff -u b/core/modules/node/node.module b/core/modules/node/node.module --- b/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -205,7 +205,8 @@ } } } - // @todo Manage base field displays in the YAML. + // @todo Manage base field displays in the YAML: + // https://drupal.org/node/2144919. $display->setComponent('title', array( 'label' => 'hidden', 'type' => 'text_default', @@ -218,7 +219,8 @@ */ function node_entity_form_display_alter(EntityFormDisplay $form_display, $context) { if ($context['entity_type'] == 'node') { - // @todo Manage base field displays in the YAML. + // @todo Manage base field displays in the YAML: + // https://drupal.org/node/2144919. $node_type = node_type_load($context['bundle']); if ($node_type->has_title) { // Title is also registered in node_field_extra_fields().