diff --git a/core/modules/field/field.info.inc b/core/modules/field/field.info.inc index c58d986..1569645 100644 --- a/core/modules/field/field.info.inc +++ b/core/modules/field/field.info.inc @@ -74,18 +74,20 @@ function field_behaviors_widget($op, $instance) { * The function only returns active, non deleted fields. * * @return - * An array keyed by field name. Each value is an array with two entries: - * - type: The field type. - * - bundles: The bundles in which the field appears, as an array with entity - * types as keys and the array of bundle names as values. + * 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. * Example: * @code * array( - * 'body' => array( - * 'bundles' => array( - * 'node' => array('page', 'article'), + * 'node' => array( + * 'body' => array( + * 'bundles' => array( + * 'page', 'article' + * ), + * 'type' => 'text_with_summary', * ), - * 'type' => 'text_with_summary', * ), * ); * @endcode diff --git a/core/modules/field/lib/Drupal/field/FieldInfo.php b/core/modules/field/lib/Drupal/field/FieldInfo.php index 9c5d490..ea21f9e 100644 --- a/core/modules/field/lib/Drupal/field/FieldInfo.php +++ b/core/modules/field/lib/Drupal/field/FieldInfo.php @@ -165,10 +165,10 @@ public function flush() { * Collects a lightweight map of fields across bundles. * * @return - * An array keyed by field name. Each value is an array with two entries: + * 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, as an array with - * entity types as keys and the array of bundle names as values. + * - bundles: The bundles in which the field appears. */ public function getFieldMap() { // Read from the "static" cache. @@ -184,6 +184,7 @@ public function getFieldMap() { $this->fieldMap = $map; return $map; + } $map = array(); @@ -192,7 +193,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['uuid']] = $field_config; + $fields[$field_config['entity_type']][$field_config['uuid']] = $field_config; } } // Get field instances. @@ -201,10 +202,10 @@ public function getFieldMap() { $field_uuid = $instance_config['field_uuid']; // Filter out instances of inactive fields, and instances on unknown // entity types. - if (isset($fields[$field_uuid])) { - $field = $fields[$field_uuid]; - $map[$field['name']]['bundles'][$instance_config['entity_type']][] = $instance_config['bundle']; - $map[$field['name']]['type'] = $field['type']; + if (isset($fields[$instance_config['entity_type']][$field_uuid])) { + $field = $fields[$instance_config['entity_type']][$field_uuid]; + $map[$instance_config['entity_type']][$field['name']]['bundles'][] = $instance_config['bundle']; + $map[$instance_config['entity_type']][$field['name']]['type'] = $field['type']; } } @@ -441,9 +442,13 @@ public function getBundleInstances($entity_type, $bundle) { // 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 $field_name => $field_data) { - if (isset($field_data['bundles'][$entity_type]) && in_array($bundle, $field_data['bundles'][$entity_type])) { - $config_ids["$entity_type.$field_name"] = "$entity_type.$bundle.$field_name"; + 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"; + } + } } } 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 4b6d001..7d0bbd9 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 @@ -419,10 +419,8 @@ public function delete() { // Delete all non-deleted instances. $instance_ids = array(); - foreach ($this->getBundles() as $entity_type => $bundles) { - foreach ($bundles as $bundle) { - $instance_ids[] = "$entity_type.$bundle.{$this->name}"; - } + foreach ($this->getBundles() as $bundle) { + $instance_ids[] = "$entity_type.$bundle.{$this->name}"; } foreach ($instance_controller->loadMultiple($instance_ids) as $instance) { // By default, FieldInstance::delete() will automatically try to delete @@ -498,8 +496,8 @@ public function getColumns() { public function getBundles() { if (empty($this->deleted)) { $map = field_info_field_map(); - if (isset($map[$this->name]['bundles'])) { - return $map[$this->name]['bundles']; + if (isset($map[$this->entity_type][$this->name]['bundles'])) { + return $map[$this->entity_type][$this->name]['bundles']; } } return array(); @@ -682,13 +680,13 @@ public function hasData() { $storage_details = $this->getSchema(); $columns = array_keys($storage_details['columns']); $factory = \Drupal::service('entity.query'); - foreach ($this->getBundles() as $entity_type => $bundle) { + foreach ($this->getBundles() as $bundle) { // Entity Query throws an exception if there is no base table. - $entity_info = \Drupal::entityManager()->getDefinition($entity_type); + $entity_info = \Drupal::entityManager()->getDefinition($this->entity_type); if (!isset($entity_info['base_table'])) { continue; } - $query = $factory->get($entity_type); + $query = $factory->get($this->entity_type); $group = $query->orConditionGroup(); foreach ($columns as $column) { $group->exists($this->name . '.' . $column); diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FieldListController.php b/core/modules/field_ui/lib/Drupal/field_ui/FieldListController.php index fbdd55a..075ffe8 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/FieldListController.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldListController.php @@ -12,7 +12,6 @@ use Drupal\Core\Entity\EntityManager; use Drupal\Core\Entity\Field\FieldTypePluginManager; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\field\FieldInfo; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -28,13 +27,6 @@ class FieldListController extends ConfigEntityListController { protected $fieldTypes; /** - * An array of field data. - * - * @var array - */ - protected $fieldInfo; - - /** * The entity manager. * * @var \Drupal\Core\Entity\EntityManager @@ -71,10 +63,9 @@ class FieldListController extends ConfigEntityListController { * @param \Drupal\Core\Entity\Field\FieldTypePluginManager $field_type_manager * The 'field type' plugin manager. */ - public function __construct($entity_type, array $entity_info, EntityManager $entity_manager, ModuleHandlerInterface $module_handler, FieldInfo $field_info, FieldTypePluginManager $field_type_manager) { + public function __construct($entity_type, array $entity_info, EntityManager $entity_manager, ModuleHandlerInterface $module_handler, FieldTypePluginManager $field_type_manager) { parent::__construct($entity_type, $entity_info, $entity_manager->getStorageController($entity_type), $module_handler); - $this->fieldInfo = $field_info->getFieldMap(); $this->entityManager = $entity_manager; $this->bundles = entity_get_bundles(); $this->fieldTypeManager = $field_type_manager; @@ -90,7 +81,6 @@ public static function createInstance(ContainerInterface $container, $entity_typ $entity_info, $container->get('plugin.manager.entity'), $container->get('module_handler'), - $container->get('field.info'), $container->get('plugin.manager.entity.field.field_type') ); } @@ -124,11 +114,9 @@ public function buildRow(EntityInterface $field) { $row['data']['type'] = t('@type (module: @module)', array('@type' => $field_type['label'], '@module' => $field_type['provider'])); $usage = array(); - foreach ($field->getBundles() as $entity_type => $field_bundles) { - foreach ($field_bundles as $bundle) { - $admin_path = $this->entityManager->getAdminPath($entity_type, $bundle); - $usage[] = $admin_path ? l($this->bundles[$entity_type][$bundle]['label'], $admin_path . '/fields') : $this->bundles[$entity_type][$bundle]['label']; - } + foreach ($field->getBundles() as $bundle) { + $admin_path = $this->entityManager->getAdminPath($field->entity_type, $bundle); + $usage[] = $admin_path ? l($this->bundles[$field->entity_type][$bundle]['label'], $admin_path . '/fields') : $this->bundles[$field->entity_type][$bundle]['label']; } $row['data']['usage'] = implode(', ', $usage); return $row;