diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php index ade534a..50ab59b 100644 --- a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php +++ b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php @@ -77,7 +77,7 @@ public function addField($field, $type, $langcode) { $field_storage_definitions = array(); // @todo Needed for menu links, make this implementation content entity - // specific after https://drupal.org/node/1842858. + // specific after https://drupal.org/node/2256521. if ($entity_type instanceof ContentEntityTypeInterface) { $field_storage_definitions = $entity_manager->getFieldStorageDefinitions($entity_type_id); } diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 364eb5a..590166f 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -104,13 +104,21 @@ function comment_entity_bundle_info() { ->execute(); $config_factory = \Drupal::configFactory(); foreach ($ids as $id) { + // @todo: We can not rely on the field map here, so we need tomanually look + // for a matching field instance to use for the label. Remove this in + // https://drupal.org/node/2228763. list($entity_type_id, $field_name) = explode('.', $id); - $instance_ids = $config_factory->listAll('field.instance.' . $id . '.'); - $instance_id = reset($instance_ids); - $config = \Drupal::config('field.instance.' . $instance_id); - $bundles['comment'][$entity_type_id . '__' . $field_name] = array( - 'label' => $config->get('label'), - ); + $instance_ids = $config_factory->listAll('field.instance.' . $entity_type_id . '.'); + // Look for an instance for this field. + foreach ($instance_ids as $instance_id) { + $instance_field_name = substr($instance_id, strrpos($instance_id, '.') + 1); + if ($instance_field_name == $field_name) { + $config = \Drupal::config($instance_id); + $bundles['comment'][$entity_type_id . '__' . $field_name] = array( + 'label' => $config->get('label'), + ); + } + } } return $bundles; } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php index d4af65e..dd0c0fe 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php @@ -42,6 +42,10 @@ function setUp() { // Create comment field on entity_test bundle. $this->container->get('comment.manager')->addDefaultField('entity_test', 'entity_test'); + // Verify that bundles are defined correctly. + $bundles = \Drupal::entityManager()->getBundleInfo('comment'); + $this->assertEqual($bundles['entity_test__comment']['label'], 'Comment settings'); + // Create test user. $this->admin_user = $this->drupalCreateUser(array( 'administer comments', diff --git a/core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationFieldInstanceListBuilder.php b/core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationFieldInstanceListBuilder.php index ff569d3..ef3b50f 100644 --- a/core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationFieldInstanceListBuilder.php +++ b/core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationFieldInstanceListBuilder.php @@ -92,7 +92,7 @@ public function load() { // It is not possible to use the standard load method, because this needs // all field instance entities only for the given baseEntityType. $ids = \Drupal::entityQuery('field_instance_config') - ->condition('entity_type', $this->baseEntityType) + ->condition('id', $this->baseEntityType . '.', 'STARTS_WITH') ->execute(); return $this->storage->loadMultiple($ids); } diff --git a/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php b/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php index 3f1f4df..ad31ede 100644 --- a/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php @@ -806,7 +806,7 @@ protected function getFieldItemClass() { * @param string $field_name * Name of the field. * - * @return static|null + * @return static * The field config entity if one exists for the provided field name, * otherwise NULL. */ diff --git a/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php index 1a418f2..d2a80dd 100644 --- a/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php @@ -231,20 +231,19 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi * @ingroup field_crud */ public function __construct(array $values, $entity_type = 'field_instance_config') { - // Load the corresponding field. - if (isset($values['field_name']) && isset($values['entity_type'])) { + // Load the corresponding field. In case the instance was deleted, load the + // field based on the UUID, otherwise use the field name. + if (!empty($values['deleted'])) { if ($fields = entity_load_multiple_by_properties('field_config', array('uuid' => $values['field_uuid'], 'include_deleted' => TRUE))) { + $field = current($fields); + } + else { + throw new FieldException(format_string('Attempt to create an instance of field @field_name that does not exist on entity type @entity_type.', array('@field_name' => $values['field_name'], '@entity_type' => $values['entity_type']))); + } + } + elseif (isset($values['field_name']) && isset($values['entity_type'])) { $field = FieldConfig::loadByName($values['entity_type'], $values['field_name']); - if (!$field) { - // The field might have been deleted, try to load it based on the UUID - // when present. - if (isset($values['field_uuid']) && isset($values['uuid'])) { - if ($fields = entity_load_multiple_by_properties('field_config', array('uuid' => $values['field_uuid'], 'include_deleted' => TRUE))) { - $field = current($fields); - } - } - if (!$field) { - throw new FieldException(format_string('Attempt to create an instance of field @field_name that does not exist on entity type @entity_type.', array('@field_name' => $values['field_name'], '@entity_type' => $values['entity_type']))); - } + if (empty($field)) { + throw new FieldException(format_string('Attempt to create an instance of field @field_name that does not exist on entity type @entity_type.', array('@field_name' => $values['field_name'], '@entity_type' => $values['entity_type']))); } $values['field_uuid'] = $field->uuid(); } @@ -813,7 +812,7 @@ public function isDeleted() { * @param string $field_name * Name of the field. * - * @return static|null + * @return static * The field instance config entity if one exists for the provided field * name, otherwise NULL. */ diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 57898a7..339eac6 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -652,8 +652,8 @@ function file_file_download($uri, $field_type = 'file') { foreach ($references as $field_name => $field_references) { foreach ($field_references as $entity_type => $entities) { $field_storage_definitions = \Drupal::entityManager()->getFieldStorageDefinitions($entity_type); + $field = $field_storage_definitions[$field_name]; foreach ($entities as $entity) { - $field = $field_storage_definitions[$field_name]; // Check if access to this field is not disallowed. if (!$entity->get($field_name)->access('view')) { $denied = TRUE; diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 3f0e54f..e8c8a12 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -115,8 +115,8 @@ function forum_menu_local_tasks(&$data, $route_name) { $vid = \Drupal::config('forum.settings')->get('vocabulary'); $links = array(); // Loop through all bundles for forum taxonomy vocabulary field. - $field = FieldConfig::loadByName('node', 'taxonomy_forums'); - foreach ($field->getBundles() as $type) { + $field_map = \Drupal::entityManager()->getFieldMap(); + foreach ($field_map['node']['taxonomy_forums']['bundles'] as $type) { if (\Drupal::entityManager()->getAccessController('node')->createAccess($type)) { $links[$type] = array( '#theme' => 'menu_local_action',