diff --git a/core/modules/field/field.info.inc b/core/modules/field/field.info.inc index 1569645..2bdb147 100644 --- a/core/modules/field/field.info.inc +++ b/core/modules/field/field.info.inc @@ -76,8 +76,8 @@ function field_behaviors_widget($op, $instance) { * @return * An array keyed by entity type. Each value is an array which keys are * field names and value is an array with two entries: - * - type: The field type. - * - bundles: The bundles in which the field appears. + * - type: The field type. + * - bundles: The bundles in which the field appears. * Example: * @code * array( diff --git a/core/modules/field/lib/Drupal/field/FieldInfo.php b/core/modules/field/lib/Drupal/field/FieldInfo.php index ea21f9e..096841d 100644 --- a/core/modules/field/lib/Drupal/field/FieldInfo.php +++ b/core/modules/field/lib/Drupal/field/FieldInfo.php @@ -184,7 +184,6 @@ public function getFieldMap() { $this->fieldMap = $map; return $map; - } $map = array(); @@ -193,7 +192,7 @@ public function getFieldMap() { foreach (config_get_storage_names_with_prefix('field.field.') as $config_id) { $field_config = $this->config->get($config_id)->get(); if ($field_config['active']) { - $fields[$field_config['entity_type']][$field_config['uuid']] = $field_config; + $fields[$field_config['uuid']] = $field_config; } } // Get field instances. @@ -202,8 +201,8 @@ public function getFieldMap() { $field_uuid = $instance_config['field_uuid']; // Filter out instances of inactive fields, and instances on unknown // entity types. - if (isset($fields[$instance_config['entity_type']][$field_uuid])) { - $field = $fields[$instance_config['entity_type']][$field_uuid]; + if (isset($fields[$field_uuid])) { + $field = $fields[$field_uuid]; $map[$instance_config['entity_type']][$field['name']]['bundles'][] = $instance_config['bundle']; $map[$instance_config['entity_type']][$field['name']]['type'] = $field['type']; } @@ -434,21 +433,18 @@ public function getBundleInstances($entity_type, $bundle) { // Cache miss: collect from the definitions. $instances = array(); + $field_map = $this->getFieldMap(); // Do not return anything for unknown entity types. - if (entity_get_info($entity_type)) { + if (entity_get_info($entity_type) && !empty($field_map[$entity_type])) { // Collect names of fields and instances involved in the bundle, using the // field map. The field map is already filtered to active, non-deleted // fields and instances, so those are kept out of the persistent caches. $config_ids = array(); - foreach ($this->getFieldMap() as $map_entity_type => $fields) { - if ($map_entity_type == $entity_type) { - foreach ($fields as $field_name => $field_data) { - if (in_array($bundle, $field_data['bundles'])) { - $config_ids["$entity_type.$field_name"] = "$entity_type.$bundle.$field_name"; - } - } + foreach ($field_map[$entity_type] as $field_name => $field_data) { + if (in_array($bundle, $field_data['bundles'])) { + $config_ids["$entity_type.$field_name"] = "$entity_type.$bundle.$field_name"; } } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php index 2a8f744..4c5b03b 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php @@ -680,26 +680,24 @@ public function hasData() { $storage_details = $this->getSchema(); $columns = array_keys($storage_details['columns']); $factory = \Drupal::service('entity.query'); - foreach ($this->getBundles() as $bundle) { - // Entity Query throws an exception if there is no base table. - $entity_info = \Drupal::entityManager()->getDefinition($this->entity_type); - if (!isset($entity_info['base_table'])) { - continue; - } - $query = $factory->get($this->entity_type); - $group = $query->orConditionGroup(); - foreach ($columns as $column) { - $group->exists($this->name . '.' . $column); - } - $result = $query - ->condition($group) - ->count() - ->accessCheck(FALSE) - ->range(0, 1) - ->execute(); - if ($result) { - return TRUE; - } + // Entity Query throws an exception if there is no base table. + $entity_info = \Drupal::entityManager()->getDefinition($this->entity_type); + if (!isset($entity_info['base_table'])) { + continue; + } + $query = $factory->get($this->entity_type); + $group = $query->orConditionGroup(); + foreach ($columns as $column) { + $group->exists($this->name . '.' . $column); + } + $result = $query + ->condition($group) + ->count() + ->accessCheck(FALSE) + ->range(0, 1) + ->execute(); + if ($result) { + return TRUE; } return FALSE;