diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php index 1d89125..88204f9 100644 --- a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php +++ b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php @@ -108,7 +108,7 @@ function addField($field, $type, $langcode) { if (substr($specifier, 0, 3) == 'id:') { $field = field_info_field_by_id(substr($specifier, 3)); } - elseif (isset($field_map[$specifier])) { + elseif (isset($field_map[$entity_type][$specifier])) { $field = field_info_field($entity_type, $specifier); } else { 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/field.views.inc b/core/modules/field/field.views.inc index 96154d5..b12bccb 100644 --- a/core/modules/field/field.views.inc +++ b/core/modules/field/field.views.inc @@ -70,10 +70,10 @@ function field_views_data_alter(&$data) { function _field_views_get_sql_entity_types(FieldInterface $field) { $sql_entity_types = array(); $entity_manager = Drupal::entityManager(); - foreach ($field['bundles'] as $entity_type => $bundles) { + foreach ($field['bundles'] as $bundle) { try { - if ($entity_manager->getStorageController($entity_type) instanceof DatabaseStorageController) { - $sql_entity_types[] = $entity_type; + if ($entity_manager->getStorageController($field->entity_type) instanceof DatabaseStorageController) { + $sql_entity_types[] = $field->entity_type; } } catch (\InvalidArgumentException $e) { @@ -197,8 +197,8 @@ function field_views_field_default_views_data(FieldInterface $field, $sql_entity $supports_revisions = TRUE; } - foreach ($field['bundles'][$entity_type] as $bundle) { - $bundles_names[] = t('@entity:@bundle', array('@entity' => $entity_type, '@bundle' => $bundle)); + foreach ($field['bundles'] as $bundle) { + $bundles_names[] = t('@entity:@bundle', array('@entity' => $field->entity_type, '@bundle' => $bundle)); } } 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..2a8f744 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[] = "{$this->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/lib/Drupal/field/Tests/FieldInfoTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php index 103acc1..ce98890 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php @@ -255,17 +255,20 @@ function testFieldMap() { } $expected = array( - 'field_1' => array( - 'type' => 'test_field', - 'bundles' => array( - 'entity_test' => array('entity_test', 'test_bundle_2'), + 'entity_test' => array( + 'field_1' => array( + 'type' => 'test_field', + 'bundles' => array('entity_test', 'test_bundle_2'), + ), + 'field_2' => array( + 'type' => 'hidden_test_field', + 'bundles' => array('entity_test'), ), ), - 'field_2' => array( - 'type' => 'hidden_test_field', - 'bundles' => array( - 'entity_test' => array('entity_test'), - 'entity_test_cache' => array('entity_test'), + 'entity_test_cache' => array( + 'field_2' => array( + 'type' => 'hidden_test_field', + 'bundles' => array('entity_test') ), ), ); 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; diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php index 39d7215..513efb3 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php @@ -497,10 +497,12 @@ protected function getExistingFieldOptions() { // entity type that are not already present in the current bundle. $field_map = field_info_field_map(); $instance_ids = array(); - foreach ($field_map as $field_name => $data) { - if (isset($data['bundles'][$this->entity_type]) && !in_array($this->bundle, $data['bundles'][$this->entity_type])) { - $bundle = reset($data['bundles'][$this->entity_type]); - $instance_ids[] = $this->entity_type . '.' . $bundle . '.' . $field_name; + if (!empty($field_map[$this->entity_type])) { + foreach ($field_map[$this->entity_type] as $field_name => $data) { + if (!in_array($this->bundle, $data['bundles'])) { + $bundle = reset($data['bundles']); + $instance_ids[] = $this->entity_type . '.' . $bundle . '.' . $field_name; + } } } diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 6b01beb..9542d54 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -172,7 +172,7 @@ function forum_menu_local_tasks(&$data, $router_item, $root_path) { $links = array(); // Loop through all bundles for forum taxonomy vocabulary field. $field = field_info_field('node', 'taxonomy_forums'); - foreach ($field['bundles']['node'] as $type_name) { + foreach ($field['bundles'] as $type_name) { if (($type = entity_load('node_type', $type_name)) && node_access('create', $type_name)) { $links[$type_name] = array( '#theme' => 'menu_local_action', diff --git a/core/modules/options/options.module b/core/modules/options/options.module index e6ebdbe..6dedc11 100644 --- a/core/modules/options/options.module +++ b/core/modules/options/options.module @@ -384,16 +384,14 @@ function _options_values_in_use($field, $values) { if ($values) { $field = field_info_field_by_id($field['uuid']); $factory = Drupal::service('entity.query'); - foreach ($field['bundles'] as $entity_type => $bundle) { - $result = $factory->get($entity_type) - ->condition($field['field_name'] . '.value', $values) - ->count() - ->accessCheck(FALSE) - ->range(0, 1) - ->execute(); - if ($result) { - return TRUE; - } + $result = $factory->get($field->entity_type) + ->condition($field['field_name'] . '.value', $values) + ->count() + ->accessCheck(FALSE) + ->range(0, 1) + ->execute(); + if ($result) { + return TRUE; } } diff --git a/core/modules/rest/lib/Drupal/rest/LinkManager/RelationLinkManager.php b/core/modules/rest/lib/Drupal/rest/LinkManager/RelationLinkManager.php index 0e3fd91..9e79bc3 100644 --- a/core/modules/rest/lib/Drupal/rest/LinkManager/RelationLinkManager.php +++ b/core/modules/rest/lib/Drupal/rest/LinkManager/RelationLinkManager.php @@ -74,14 +74,14 @@ public function getRelations() { protected function writeCache() { $data = array(); - foreach (field_info_fields() as $field_info) { - foreach ($field_info['bundles'] as $entity_type => $bundles) { - foreach ($bundles as $bundle) { - $relation_uri = $this->getRelationUri($entity_type, $bundle, $field_info['field_name']); + foreach (field_info_fields() as $entity_type => $fields) { + foreach ($fields as $field_name => $field_info) { + foreach ($field_info['bundles'] as $bundle) { + $relation_uri = $this->getRelationUri($entity_type, $bundle, $field_name); $data[$relation_uri] = array( 'entity_type' => $entity_type, 'bundle' => $bundle, - 'field_name' => $field_info['field_name'], + 'field_name' => $field_name, ); } }