Commit a820153f authored by alexpott's avatar alexpott

Issue #1735118 by swentel, yched, xjm, larowlan, alexpott, tim.plunkett: Convert Field API to CMI.

parent 5a6647be
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
use Drupal\Component\Plugin\Discovery\DiscoveryInterface; use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\field\Plugin\PluginSettingsBase; use Drupal\field\Plugin\PluginSettingsBase;
use Drupal\field\FieldInstance; use Drupal\field\Plugin\Core\Entity\FieldInstance;
use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\datetime\DateHelper; use Drupal\datetime\DateHelper;
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
use Drupal\Component\Plugin\Discovery\DiscoveryInterface; use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\field\Plugin\PluginSettingsBase; use Drupal\field\Plugin\PluginSettingsBase;
use Drupal\field\FieldInstance; use Drupal\field\Plugin\Core\Entity\FieldInstance;
use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Datetime\DrupalDateTime;
/** /**
......
...@@ -48,13 +48,12 @@ function setUp() { ...@@ -48,13 +48,12 @@ function setUp() {
$this->drupalLogin($web_user); $this->drupalLogin($web_user);
// Create a field with settings to validate. // Create a field with settings to validate.
$this->field = array( $this->field = field_create_field(array(
'field_name' => drupal_strtolower($this->randomName()), 'field_name' => drupal_strtolower($this->randomName()),
'type' => 'datetime', 'type' => 'datetime',
'settings' => array('datetime_type' => 'date'), 'settings' => array('datetime_type' => 'date'),
); ));
field_create_field($this->field); $this->instance = field_create_instance(array(
$this->instance = array(
'field_name' => $this->field['field_name'], 'field_name' => $this->field['field_name'],
'entity_type' => 'test_entity', 'entity_type' => 'test_entity',
'bundle' => 'test_bundle', 'bundle' => 'test_bundle',
...@@ -64,8 +63,7 @@ function setUp() { ...@@ -64,8 +63,7 @@ function setUp() {
'settings' => array( 'settings' => array(
'default_value' => 'blank', 'default_value' => 'blank',
), ),
); ));
field_create_instance($this->instance);
$this->display_options = array( $this->display_options = array(
'type' => 'datetime_default', 'type' => 'datetime_default',
...@@ -304,6 +302,7 @@ function testDefaultValue() { ...@@ -304,6 +302,7 @@ function testDefaultValue() {
// Set the default value to 'blank'. // Set the default value to 'blank'.
$this->instance['settings']['default_value'] = 'blank'; $this->instance['settings']['default_value'] = 'blank';
$this->instance['default_value_function'] = 'datetime_default_value';
field_update_instance($this->instance); field_update_instance($this->instance);
// Display creation form. // Display creation form.
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
use Drupal\Component\Plugin\PluginBase; use Drupal\Component\Plugin\PluginBase;
use Drupal\edit\EditorInterface; use Drupal\edit\EditorInterface;
use Drupal\field\FieldInstance; use Drupal\field\Plugin\Core\Entity\FieldInstance;
/** /**
* Defines a base editor (Create.js PropertyEditor widget) implementation. * Defines a base editor (Create.js PropertyEditor widget) implementation.
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
namespace Drupal\edit; namespace Drupal\edit;
use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Component\Plugin\PluginInspectionInterface;
use Drupal\field\FieldInstance; use Drupal\field\Plugin\Core\Entity\FieldInstance;
/** /**
* Defines an interface for in-place editors (Create.js PropertyEditor widgets). * Defines an interface for in-place editors (Create.js PropertyEditor widgets).
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Component\Utility\NestedArray; use Drupal\Component\Utility\NestedArray;
use Drupal\field\FieldInstance; use Drupal\field\Plugin\Core\Entity\FieldInstance;
/** /**
* Selects an in-place editor (an Editor plugin) for a field. * Selects an in-place editor (an Editor plugin) for a field.
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
namespace Drupal\edit; namespace Drupal\edit;
use Drupal\field\FieldInstance; use Drupal\field\Plugin\Core\Entity\FieldInstance;
/** /**
* Interface for selecting an in-place editor (an Editor plugin) for a field. * Interface for selecting an in-place editor (an Editor plugin) for a field.
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\field\FieldInstance; use Drupal\field\Plugin\Core\Entity\FieldInstance;
use Drupal\edit\Access\EditEntityFieldAccessCheckInterface; use Drupal\edit\Access\EditEntityFieldAccessCheckInterface;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
namespace Drupal\edit; namespace Drupal\edit;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\field\FieldInstance; use Drupal\field\Plugin\Core\Entity\FieldInstance;
/** /**
* Interface for generating in-place editing metadata for an entity field. * Interface for generating in-place editing metadata for an entity field.
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
use Drupal\edit\EditorBase; use Drupal\edit\EditorBase;
use Drupal\Component\Annotation\Plugin; use Drupal\Component\Annotation\Plugin;
use Drupal\field\FieldInstance; use Drupal\field\Plugin\Core\Entity\FieldInstance;
/** /**
* Defines the "direct" Create.js PropertyEditor widget. * Defines the "direct" Create.js PropertyEditor widget.
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
use Drupal\edit\EditorBase; use Drupal\edit\EditorBase;
use Drupal\Component\Annotation\Plugin; use Drupal\Component\Annotation\Plugin;
use Drupal\field\FieldInstance; use Drupal\field\Plugin\Core\Entity\FieldInstance;
/** /**
* Defines the "form" Create.js PropertyEditor widget. * Defines the "form" Create.js PropertyEditor widget.
......
...@@ -28,7 +28,6 @@ function setUp() { ...@@ -28,7 +28,6 @@ function setUp() {
parent::setUp(); parent::setUp();
$this->installSchema('system', 'variable'); $this->installSchema('system', 'variable');
$this->installSchema('field', array('field_config', 'field_config_instance'));
$this->installSchema('entity_test', array('entity_test', 'entity_test_rev')); $this->installSchema('entity_test', array('entity_test', 'entity_test_rev'));
// Set default storage backend. // Set default storage backend.
...@@ -58,12 +57,12 @@ function setUp() { ...@@ -58,12 +57,12 @@ function setUp() {
*/ */
function createFieldWithInstance($field_name, $type, $cardinality, $label, $instance_settings, $widget_type, $widget_settings, $formatter_type, $formatter_settings) { function createFieldWithInstance($field_name, $type, $cardinality, $label, $instance_settings, $widget_type, $widget_settings, $formatter_type, $formatter_settings) {
$field = $field_name . '_field'; $field = $field_name . '_field';
$this->$field = array( $this->field = array(
'field_name' => $field_name, 'field_name' => $field_name,
'type' => $type, 'type' => $type,
'cardinality' => $cardinality, 'cardinality' => $cardinality,
); );
$this->$field_name = field_create_field($this->$field); $this->$field = field_create_field($this->field);
$instance = $field_name . '_instance'; $instance = $field_name . '_instance';
$this->$instance = array( $this->$instance = array(
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
use Drupal\edit\EditorBase; use Drupal\edit\EditorBase;
use Drupal\Component\Annotation\Plugin; use Drupal\Component\Annotation\Plugin;
use Drupal\field\FieldInstance; use Drupal\field\Plugin\Core\Entity\FieldInstance;
/** /**
* Defines the "wysiwyg" Create.js PropertyEditor widget. * Defines the "wysiwyg" Create.js PropertyEditor widget.
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
use Drupal\Component\Annotation\Plugin; use Drupal\Component\Annotation\Plugin;
use Drupal\Core\Annotation\Translation; use Drupal\Core\Annotation\Translation;
use Drupal\edit\EditorInterface; use Drupal\edit\EditorInterface;
use Drupal\field\FieldInstance; use Drupal\field\Plugin\Core\Entity\FieldInstance;
/** /**
......
...@@ -24,12 +24,6 @@ public static function getInfo() { ...@@ -24,12 +24,6 @@ public static function getInfo() {
); );
} }
protected function setUp() {
parent::setUp();
$this->installSchema('field', array('field_config', 'field_config_instance'));
}
/** /**
* Tests basic CRUD operations on EntityDisplay objects. * Tests basic CRUD operations on EntityDisplay objects.
*/ */
......
...@@ -234,6 +234,9 @@ function hook_field_info_alter(&$info) { ...@@ -234,6 +234,9 @@ function hook_field_info_alter(&$info) {
* indexes specified by the field-type module. Some storage engines might * indexes specified by the field-type module. Some storage engines might
* not support indexes. * not support indexes.
* - foreign keys: (optional) An array of Schema API foreign key definitions. * - foreign keys: (optional) An array of Schema API foreign key definitions.
* Note, however, that the field data is not necessarily stored in SQL.
* Also, the possible usage is limited, as you cannot specify another field
* as related, only existing SQL tables, such as {taxonomy_term_data}.
*/ */
function hook_field_schema($field) { function hook_field_schema($field) {
if ($field['type'] == 'text_long') { if ($field['type'] == 'text_long') {
...@@ -1302,7 +1305,7 @@ function hook_field_storage_details_alter(&$details, $field) { ...@@ -1302,7 +1305,7 @@ function hook_field_storage_details_alter(&$details, $field) {
* FIELD_LOAD_REVISION to load the version indicated by each entity. * FIELD_LOAD_REVISION to load the version indicated by each entity.
* @param $fields * @param $fields
* An array listing the fields to be loaded. The keys of the array are field * An array listing the fields to be loaded. The keys of the array are field
* IDs, and the values of the array are the entity IDs (or revision IDs, * UUIDs, and the values of the array are the entity IDs (or revision IDs,
* depending on the $age parameter) to add each field to. * depending on the $age parameter) to add each field to.
* @param $options * @param $options
* An associative array of additional options, with the following keys: * An associative array of additional options, with the following keys:
...@@ -1370,7 +1373,7 @@ function hook_field_storage_load($entity_type, $entities, $age, $fields, $option ...@@ -1370,7 +1373,7 @@ function hook_field_storage_load($entity_type, $entities, $age, $fields, $option
* FIELD_STORAGE_INSERT when inserting a new entity. * FIELD_STORAGE_INSERT when inserting a new entity.
* @param $fields * @param $fields
* An array listing the fields to be written. The keys and values of the * An array listing the fields to be written. The keys and values of the
* array are field IDs. * array are field UUIDs.
*/ */
function hook_field_storage_write(\Drupal\Core\Entity\EntityInterface $entity, $op, $fields) { function hook_field_storage_write(\Drupal\Core\Entity\EntityInterface $entity, $op, $fields) {
$id = $entity->id(); $id = $entity->id();
...@@ -1464,7 +1467,7 @@ function hook_field_storage_write(\Drupal\Core\Entity\EntityInterface $entity, $ ...@@ -1464,7 +1467,7 @@ function hook_field_storage_write(\Drupal\Core\Entity\EntityInterface $entity, $
* The entity on which to operate. * The entity on which to operate.
* @param $fields * @param $fields
* An array listing the fields to delete. The keys and values of the * An array listing the fields to delete. The keys and values of the
* array are field IDs. * array are field UUIDs.
*/ */
function hook_field_storage_delete(\Drupal\Core\Entity\EntityInterface $entity, $fields) { function hook_field_storage_delete(\Drupal\Core\Entity\EntityInterface $entity, $fields) {
foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) { foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) {
...@@ -1488,7 +1491,7 @@ function hook_field_storage_delete(\Drupal\Core\Entity\EntityInterface $entity, ...@@ -1488,7 +1491,7 @@ function hook_field_storage_delete(\Drupal\Core\Entity\EntityInterface $entity,
* The entity on which to operate. * The entity on which to operate.
* @param $fields * @param $fields
* An array listing the fields to delete. The keys and values of the * An array listing the fields to delete. The keys and values of the
* array are field IDs. * array are field UUIDs.
*/ */
function hook_field_storage_delete_revision(\Drupal\Core\Entity\EntityInterface $entity, $fields) { function hook_field_storage_delete_revision(\Drupal\Core\Entity\EntityInterface $entity, $fields) {
$vid = $entity->getRevisionId(); $vid = $entity->getRevisionId();
...@@ -1712,13 +1715,13 @@ function hook_field_storage_delete_instance($instance) { ...@@ -1712,13 +1715,13 @@ function hook_field_storage_delete_instance($instance) {
* FIELD_LOAD_CURRENT to load the most recent revision for all fields, or * FIELD_LOAD_CURRENT to load the most recent revision for all fields, or
* FIELD_LOAD_REVISION to load the version indicated by each entity. * FIELD_LOAD_REVISION to load the version indicated by each entity.
* @param $skip_fields * @param $skip_fields
* An array keyed by field IDs whose data has already been loaded and * An array keyed by field UUIDs whose data has already been loaded and
* therefore should not be loaded again. Add a key to this array to indicate * therefore should not be loaded again. Add a key to this array to indicate
* that your module has already loaded a field. * that your module has already loaded a field.
* @param $options * @param $options
* An associative array of additional options, with the following keys: * An associative array of additional options, with the following keys:
* - field_id: The field ID that should be loaded. If unset, all fields should * - field_id: The field UUID that should be loaded. If unset, all fields
* be loaded. * should be loaded.
* - deleted: If TRUE, deleted fields should be loaded as well as non-deleted * - deleted: If TRUE, deleted fields should be loaded as well as non-deleted
* fields. If unset or FALSE, only non-deleted fields should be loaded. * fields. If unset or FALSE, only non-deleted fields should be loaded.
*/ */
...@@ -1735,11 +1738,11 @@ function hook_field_storage_pre_load($entity_type, $entities, $age, &$skip_field ...@@ -1735,11 +1738,11 @@ function hook_field_storage_pre_load($entity_type, $entities, $age, &$skip_field
* @param \Drupal\Core\Entity\EntityInterface $entity * @param \Drupal\Core\Entity\EntityInterface $entity
* The entity with fields to save. * The entity with fields to save.
* @param $skip_fields * @param $skip_fields
* An array keyed by field IDs whose data has already been written and * An array keyed by field UUIDs whose data has already been written and
* therefore should not be written again. The values associated with these * therefore should not be written again. The values associated with these
* keys are not specified. * keys are not specified.
* @return * @return
* Saved field IDs are set set as keys in $skip_fields. * Saved field UUIDs are set as keys in $skip_fields.
*/ */
function hook_field_storage_pre_insert(\Drupal\Core\Entity\EntityInterface $entity, &$skip_fields) { function hook_field_storage_pre_insert(\Drupal\Core\Entity\EntityInterface $entity, &$skip_fields) {
if ($entity->entityType() == 'node' && $entity->status && _forum_node_check_node_type($entity)) { if ($entity->entityType() == 'node' && $entity->status && _forum_node_check_node_type($entity)) {
...@@ -1770,11 +1773,11 @@ function hook_field_storage_pre_insert(\Drupal\Core\Entity\EntityInterface $enti ...@@ -1770,11 +1773,11 @@ function hook_field_storage_pre_insert(\Drupal\Core\Entity\EntityInterface $enti
* @param \Drupal\Core\Entity\EntityInterface $entity * @param \Drupal\Core\Entity\EntityInterface $entity
* The entity with fields to save. * The entity with fields to save.
* @param $skip_fields * @param $skip_fields
* An array keyed by field IDs whose data has already been written and * An array keyed by field UUIDs whose data has already been written and
* therefore should not be written again. The values associated with these * therefore should not be written again. The values associated with these
* keys are not specified. * keys are not specified.
* @return * @return
* Saved field IDs are set set as keys in $skip_fields. * Saved field UUIDs are set as keys in $skip_fields.
*/ */
function hook_field_storage_pre_update(\Drupal\Core\Entity\EntityInterface $entity, &$skip_fields) { function hook_field_storage_pre_update(\Drupal\Core\Entity\EntityInterface $entity, &$skip_fields) {
$first_call = &drupal_static(__FUNCTION__, array()); $first_call = &drupal_static(__FUNCTION__, array());
......
...@@ -1170,7 +1170,7 @@ function field_attach_insert(EntityInterface $entity) { ...@@ -1170,7 +1170,7 @@ function field_attach_insert(EntityInterface $entity) {
$storages = array(); $storages = array();
foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) { foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) {
$field = field_info_field_by_id($instance['field_id']); $field = field_info_field_by_id($instance['field_id']);
$field_id = $field['id']; $field_id = $field['uuid'];
$field_name = $field['field_name']; $field_name = $field['field_name'];
if (!empty($entity->$field_name)) { if (!empty($entity->$field_name)) {
// Collect the storage backend if the field has not been written yet. // Collect the storage backend if the field has not been written yet.
...@@ -1211,7 +1211,7 @@ function field_attach_update(EntityInterface $entity) { ...@@ -1211,7 +1211,7 @@ function field_attach_update(EntityInterface $entity) {
$storages = array(); $storages = array();
foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) { foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) {
$field = field_info_field_by_id($instance['field_id']); $field = field_info_field_by_id($instance['field_id']);
$field_id = $field['id']; $field_id = $field['uuid'];
$field_name = $field['field_name']; $field_name = $field['field_name'];
// Leave the field untouched if $entity comes with no $field_name property, // Leave the field untouched if $entity comes with no $field_name property,
// but empty the field if it comes as a NULL value or an empty array. // but empty the field if it comes as a NULL value or an empty array.
...@@ -1254,7 +1254,7 @@ function field_attach_delete(EntityInterface $entity) { ...@@ -1254,7 +1254,7 @@ function field_attach_delete(EntityInterface $entity) {
$storages = array(); $storages = array();
foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) { foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) {
$field = field_info_field_by_id($instance['field_id']); $field = field_info_field_by_id($instance['field_id']);
$field_id = $field['id']; $field_id = $field['uuid'];
$storages[$field['storage']['type']][$field_id] = $field_id; $storages[$field['storage']['type']][$field_id] = $field_id;
} }
...@@ -1287,7 +1287,7 @@ function field_attach_delete_revision(EntityInterface $entity) { ...@@ -1287,7 +1287,7 @@ function field_attach_delete_revision(EntityInterface $entity) {
$storages = array(); $storages = array();
foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) { foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) {
$field = field_info_field_by_id($instance['field_id']); $field = field_info_field_by_id($instance['field_id']);
$field_id = $field['id']; $field_id = $field['uuid'];
$storages[$field['storage']['type']][$field_id] = $field_id; $storages[$field['storage']['type']][$field_id] = $field_id;
} }
...@@ -1531,11 +1531,16 @@ function field_entity_bundle_create($entity_type, $bundle) { ...@@ -1531,11 +1531,16 @@ function field_entity_bundle_create($entity_type, $bundle) {
* Implements hook_entity_bundle_rename(). * Implements hook_entity_bundle_rename().
*/ */
function field_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) { function field_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) {
db_update('field_config_instance') $instances = field_read_instances();
->fields(array('bundle' => $bundle_new)) foreach ($instances as $instance) {
->condition('entity_type', $entity_type) if ($instance->entity_type == $entity_type && $instance->bundle == $bundle_old) {
->condition('bundle', $bundle_old) $id_new = $instance['entity_type'] . '.' . $bundle_new . '.' . $instance['field_name'];
->execute(); $instance->id = $id_new;
$instance->bundle = $bundle_new;
$instance->allowBundleRename();
$instance->save();
}
}
// Clear the cache. // Clear the cache.
field_cache_clear(); field_cache_clear();
......
This diff is collapsed.
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Field Info API, providing information about available fields and field types. * Field Info API, providing information about available fields and field types.
*/ */
use Drupal\field\FieldInstance; use Drupal\field\Plugin\Core\Entity\FieldInstance;
use Drupal\field\FieldInfo; use Drupal\field\FieldInfo;
/** /**
......
...@@ -3,6 +3,4 @@ description: 'Field API to add fields to entities like nodes and users.' ...@@ -3,6 +3,4 @@ description: 'Field API to add fields to entities like nodes and users.'
package: Core package: Core
version: VERSION version: VERSION
core: 8.x core: 8.x
dependencies:
- field_sql_storage
required: true required: true
This diff is collapsed.
This diff is collapsed.
...@@ -72,7 +72,7 @@ function field_views_field_label($field_name) { ...@@ -72,7 +72,7 @@ function field_views_field_label($field_name) {
foreach ($instances as $entity_name => $entity_type) { foreach ($instances as $entity_name => $entity_type) {
foreach ($entity_type as $bundle) { foreach ($entity_type as $bundle) {
if (isset($bundle[$field_name])) { if (isset($bundle[$field_name])) {
$label_counter[$bundle[$field_name]['label']] = isset($label_counter[$bundle[$field_name]['label']]) ? ++$label_counter[$bundle[$field_name]['label']] : 1; $label_counter[$bundle[$field_name]['label']] = isset($label_counter[$bundle[$field_name]['label']]) ? ++$label_counter[$bundle[$field_name]->label] : 1;
$all_labels[$entity_name][$bundle[$field_name]['label']] = TRUE; $all_labels[$entity_name][$bundle[$field_name]['label']] = TRUE;
} }
} }
...@@ -296,10 +296,10 @@ function field_views_field_default_views_data($field) { ...@@ -296,10 +296,10 @@ function field_views_field_default_views_data($field) {
else { else {
$group = t('@group (historical data)', array('@group' => $group_name)); $group = t('@group (historical data)', array('@group' => $group_name));
} }
$column_real_name = $field['storage']['details']['sql'][$type][$table][$column]; $column_real_name = $field['storage_details']['sql'][$type][$table][$column];
// Load all the fields from the table by default. // Load all the fields from the table by default.
$additional_fields = array_values($field['storage']['details']['sql'][$type][$table]); $additional_fields = array_values($field['storage_details']['sql'][$type][$table]);
$data[$table][$column_real_name] = array( $data[$table][$column_real_name] = array(
'group' => $group, 'group' => $group,
......
...@@ -142,17 +142,24 @@ public function getFieldMap() { ...@@ -142,17 +142,24 @@ public function getFieldMap() {
$map = array(); $map = array();
$query = db_select('field_config_instance', 'fci'); // Get active fields.
$query->join('field_config', 'fc', 'fc.id = fci.field_id'); foreach (config_get_storage_names_with_prefix('field.field') as $config_id) {
$query->fields('fc', array('type')); $field_config = \Drupal::config($config_id)->get();
$query->fields('fci', array('field_name', 'entity_type', 'bundle')) if ($field_config['active'] && $field_config['storage']['active']) {
->condition('fc.active', 1) $fields[$field_config['uuid']] = $field_config;
->condition('fc.storage_active', 1) }
->condition('fc.deleted', 0) }
->condition('fci.deleted', 0); // Get field instances.
foreach ($query->execute() as $row) { foreach (config_get_storage_names_with_prefix('field.instance') as $config_id) {
$map[$row->field_name]['bundles'][$row->entity_type][] = $row->bundle; $instance_config = \Drupal::config($config_id)->get();
$map[$row->field_name]['type'] = $row->type; $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['id']]['bundles'][$instance_config['entity_type']][] = $instance_config['bundle'];
$map[$field['id']]['type'] = $field['type'];
}
} }