Commit 6d27e11a authored by webchick's avatar webchick

Issue #2100343 by Berdir, fago, martin107, visabhishek, sriharsha.uppuluri,...

Issue #2100343 by Berdir, fago, martin107, visabhishek, sriharsha.uppuluri, Yorirou: Remove 'fieldable' key in entity definitions in favour of 'field_ui_base_route'.
parent d97f60e3
......@@ -68,11 +68,11 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) {
parent::postSave($storage, $update);
if (!$update) {
$this->entityManager()->onBundleCreate($this->getEntityType()->getBundleOf(), $this->id());
$this->entityManager()->onBundleCreate($this->id(), $this->getEntityType()->getBundleOf());
}
elseif ($this->getOriginalId() != $this->id()) {
$this->renameDisplays();
$this->entityManager()->onBundleRename($this->getEntityType()->getBundleOf(), $this->getOriginalId(), $this->id());
$this->entityManager()->onBundleRename($this->getOriginalId(), $this->id(), $this->getEntityType()->getBundleOf());
}
}
......@@ -84,7 +84,7 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti
foreach ($entities as $entity) {
$entity->deleteDisplays();
\Drupal::entityManager()->onBundleDelete($entity->getEntityType()->getBundleOf(), $entity->id());
\Drupal::entityManager()->onBundleDelete($entity->id(), $entity->getEntityType()->getBundleOf());
}
}
......
......@@ -12,7 +12,7 @@
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class ContentEntityStorageBase extends EntityStorageBase implements FieldableEntityStorageInterface {
abstract class ContentEntityStorageBase extends EntityStorageBase implements DynamicallyFieldableEntityStorageInterface {
/**
* The entity bundle key.
......@@ -103,21 +103,6 @@ public function onFieldDefinitionUpdate(FieldDefinitionInterface $field_definiti
*/
public function onFieldDefinitionDelete(FieldDefinitionInterface $field_definition) { }
/**
* {@inheritdoc}
*/
public function onBundleCreate($bundle) { }
/**
* {@inheritdoc}
*/
public function onBundleRename($bundle, $bundle_new) { }
/**
* {@inheritdoc}
*/
public function onBundleDelete($bundle) { }
/**
* {@inheritdoc}
*/
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\Core\Entity\FieldableEntityStorageInterface.
* Contains \Drupal\Core\Entity\DynamicallyFieldableEntityStorageInterface.
*/
namespace Drupal\Core\Entity;
......@@ -11,8 +11,16 @@
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionListenerInterface;
interface FieldableEntityStorageInterface extends EntityStorageInterface, FieldStorageDefinitionListenerInterface {
/**
* A storage that supports entity types with dynamic field definitions.
*
* A storage that implements this interface can react to the entity type's field
* definitions changing, due to modules being installed or uninstalled, or via
* field UI, or via code changes to the entity class.
*
* For example, configurable fields defined and exposed by field.module.
*/
interface DynamicallyFieldableEntityStorageInterface extends EntityStorageInterface, FieldStorageDefinitionListenerInterface {
/**
* Reacts to the creation of a field.
*
......@@ -44,36 +52,6 @@ public function onFieldDefinitionUpdate(FieldDefinitionInterface $field_definiti
*/
public function onFieldDefinitionDelete(FieldDefinitionInterface $field_definition);
/**
* Reacts to a bundle being created.
*
* @param string $bundle
* The name of the bundle created.
*/
public function onBundleCreate($bundle);
/**
* Reacts to a bundle being renamed.
*
* This method runs before fields are updated with the new bundle name.
*
* @param string $bundle
* The name of the bundle being renamed.
* @param string $bundle_new
* The new name of the bundle.
*/
public function onBundleRename($bundle, $bundle_new);
/**
* Reacts to a bundle being deleted.
*
* This method runs before fields are deleted.
*
* @param string $bundle
* The name of the bundle being deleted.
*/
public function onBundleDelete($bundle);
/**
* Purges a batch of field data.
*
......
<?php
/**
* @file
* Contains \Drupal\Core\Entity\EntityBundleListenerInterface.
*/
namespace Drupal\Core\Entity;
/**
* An interface for reacting to entity bundle creation, deletion, and renames.
*
* @todo Convert to Symfony events: https://www.drupal.org/node/2332935
*/
interface EntityBundleListenerInterface {
/**
* Reacts to a bundle being created.
*
* @param string $bundle
* The name of the bundle created.
* @param string $entity_type_id
* The entity type to which the bundle is bound; e.g. 'node' or 'user'.
*/
public function onBundleCreate($bundle, $entity_type_id);
/**
* Reacts to a bundle being renamed.
*
* This method runs before fields are updated with the new bundle name.
*
* @param string $bundle
* The name of the bundle being renamed.
* @param string $bundle_new
* The new name of the bundle.
* @param string $entity_type_id
* The entity type to which the bundle is bound; e.g. 'node' or 'user'.
*/
public function onBundleRename($bundle, $bundle_new, $entity_type_id);
/**
* Reacts to a bundle being deleted.
*
* This method runs before fields are deleted.
*
* @param string $bundle
* The name of the bundle being deleted.
* @param string $entity_type_id
* The entity type to which the bundle is bound; e.g. 'node' or 'user'.
*/
public function onBundleDelete($bundle, $entity_type_id);
}
......@@ -8,7 +8,7 @@
namespace Drupal\Core\Entity;
use Drupal\Core\Entity\Schema\EntityStorageSchemaInterface;
use Drupal\Core\Entity\Schema\FieldableEntityStorageSchemaInterface;
use Drupal\Core\Entity\Schema\DynamicallyFieldableEntityStorageSchemaInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
......@@ -171,7 +171,7 @@ protected function getChangeList() {
$change_list[$entity_type_id]['entity_type'] = static::DEFINITION_UPDATED;
}
if ($entity_type->isFieldable()) {
if ($this->entityManager->getStorage($entity_type_id) instanceof DynamicallyFieldableEntityStorageInterface) {
$field_changes = array();
$storage_definitions = $this->entityManager->getFieldStorageDefinitions($entity_type_id);
$original_storage_definitions = $this->entityManager->getLastInstalledFieldStorageDefinitions($entity_type_id);
......@@ -238,7 +238,7 @@ protected function requiresEntityStorageSchemaChanges(EntityTypeInterface $entit
*/
protected function requiresFieldStorageSchemaChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) {
$storage = $this->entityManager->getStorage($storage_definition->getTargetEntityTypeId());
return ($storage instanceof FieldableEntityStorageSchemaInterface) && $storage->requiresFieldStorageSchemaChanges($storage_definition, $original);
return ($storage instanceof DynamicallyFieldableEntityStorageSchemaInterface) && $storage->requiresFieldStorageSchemaChanges($storage_definition, $original);
}
}
......@@ -987,7 +987,7 @@ public function onEntityTypeCreate(EntityTypeInterface $entity_type) {
}
$this->setLastInstalledDefinition($entity_type);
if ($entity_type->isFieldable()) {
if ($entity_type->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface')) {
$this->setLastInstalledFieldStorageDefinitions($entity_type_id, $this->getFieldStorageDefinitions($entity_type_id));
}
}
......@@ -1078,12 +1078,12 @@ public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $
/**
* {@inheritdoc}
*/
public function onBundleCreate($entity_type_id, $bundle) {
public function onBundleCreate($bundle, $entity_type_id) {
$this->clearCachedBundles();
// Notify the entity storage.
$storage = $this->getStorage($entity_type_id);
if ($storage instanceof FieldableEntityStorageInterface) {
$storage->onBundleCreate($bundle);
if ($storage instanceof EntityBundleListenerInterface) {
$storage->onBundleCreate($bundle, $entity_type_id);
}
// Invoke hook_entity_bundle_create() hook.
$this->moduleHandler->invokeAll('entity_bundle_create', array($entity_type_id, $bundle));
......@@ -1092,12 +1092,12 @@ public function onBundleCreate($entity_type_id, $bundle) {
/**
* {@inheritdoc}
*/
public function onBundleRename($entity_type_id, $bundle_old, $bundle_new) {
public function onBundleRename($bundle_old, $bundle_new, $entity_type_id) {
$this->clearCachedBundles();
// Notify the entity storage.
$storage = $this->getStorage($entity_type_id);
if ($storage instanceof FieldableEntityStorageInterface) {
$storage->onBundleRename($bundle_old, $bundle_new);
if ($storage instanceof EntityBundleListenerInterface) {
$storage->onBundleRename($bundle_old, $bundle_new, $entity_type_id);
}
// Rename existing base field bundle overrides.
......@@ -1117,12 +1117,12 @@ public function onBundleRename($entity_type_id, $bundle_old, $bundle_new) {
/**
* {@inheritdoc}
*/
public function onBundleDelete($entity_type_id, $bundle) {
public function onBundleDelete($bundle, $entity_type_id) {
$this->clearCachedBundles();
// Notify the entity storage.
$storage = $this->getStorage($entity_type_id);
if ($storage instanceof FieldableEntityStorageInterface) {
$storage->onBundleDelete($bundle);
if ($storage instanceof EntityBundleListenerInterface) {
$storage->onBundleDelete($bundle, $entity_type_id);
}
// Invoke hook_entity_bundle_delete() hook.
$this->moduleHandler->invokeAll('entity_bundle_delete', array($entity_type_id, $bundle));
......
......@@ -13,7 +13,7 @@
/**
* Provides an interface for entity type managers.
*/
interface EntityManagerInterface extends PluginManagerInterface, EntityTypeListenerInterface, FieldStorageDefinitionListenerInterface {
interface EntityManagerInterface extends PluginManagerInterface, EntityTypeListenerInterface, EntityBundleListenerInterface, FieldStorageDefinitionListenerInterface {
/**
* Builds a list of entity type labels suitable for a Form API options list.
......@@ -465,42 +465,4 @@ public function loadEntityByUuid($entity_type_id, $uuid);
*/
public function getEntityTypeFromClass($class_name);
/**
* Reacts to the creation of a entity bundle.
*
* @param string $entity_type_id
* The entity type to which the bundle is bound; e.g. 'node' or 'user'.
* @param string $bundle
* The name of the bundle.
*
* @see entity_crud
*/
public function onBundleCreate($entity_type_id, $bundle);
/**
* Reacts to the rename of a entity bundle.
*
* @param string $entity_type_id
* The entity type to which the bundle is bound; e.g. 'node' or 'user'.
* @param string $bundle_old
* The previous name of the bundle.
* @param string $bundle_new
* The new name of the bundle.
*
* @see entity_crud
*/
public function onBundleRename($entity_type_id, $bundle_old, $bundle_new);
/**
* Reacts to the deletion of a entity bundle.
*
* @param string $entity_type_id
* The entity type to which the bundle is bound; e.g. 'node' or 'user'.
* @param string $bundle
* The bundle that was just deleted.
*
* @see entity_crud
*/
public function onBundleDelete($entity_type_id, $bundle);
}
......@@ -101,14 +101,6 @@ class EntityType implements EntityTypeInterface {
* @var string
*/
protected $permission_granularity = 'entity_type';
/**
* Indicates whether fields can be attached to entities of this type.
*
* @var bool
*/
protected $fieldable = FALSE;
/**
* Link templates using the URI template syntax.
*
......@@ -500,13 +492,6 @@ public function getPermissionGranularity() {
return $this->permission_granularity;
}
/**
* {@inheritdoc}
*/
public function isFieldable() {
return $this->fieldable;
}
/**
* {@inheritdoc}
*/
......
......@@ -395,14 +395,6 @@ public function getAdminPermission();
*/
public function getPermissionGranularity();
/**
* Indicates whether fields can be attached to entities of this type.
*
* @return bool
* Returns TRUE if the entity type can has fields, otherwise FALSE.
*/
public function isFieldable();
/**
* Returns link templates using the URI template syntax.
*
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\Core\Entity\Schema\FieldableEntityStorageSchemaInterface.
* Contains \Drupal\Core\Entity\Schema\DynamicallyFieldableEntityStorageSchemaInterface.
*/
namespace Drupal\Core\Entity\Schema;
......@@ -11,9 +11,15 @@
use Drupal\Core\Field\FieldStorageDefinitionListenerInterface;
/**
* Defines the interface for storage schema classes for fieldable entity types.
* A storage schema that supports entity types with dynamic field definitions.
*
* A storage schema that implements this interface can react to the entity
* type's field definitions changing, due to modules being installed or
* uninstalled, or via field UI, or via code changes to the entity class.
*
* For example, configurable fields defined and exposed by field.module.
*/
interface FieldableEntityStorageSchemaInterface extends EntityStorageSchemaInterface, FieldStorageDefinitionListenerInterface {
interface DynamicallyFieldableEntityStorageSchemaInterface extends EntityStorageSchemaInterface, FieldStorageDefinitionListenerInterface {
/**
* Checks if the changes to the storage definition requires schema changes.
......
......@@ -13,12 +13,13 @@
use Drupal\Core\Database\Database;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\ContentEntityStorageBase;
use Drupal\Core\Entity\EntityBundleListenerInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\Entity\Schema\FieldableEntityStorageSchemaInterface;
use Drupal\Core\Entity\Schema\DynamicallyFieldableEntityStorageSchemaInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Language\LanguageInterface;
......@@ -38,7 +39,7 @@
*
* @ingroup entity_api
*/
class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEntityStorageInterface, FieldableEntityStorageSchemaInterface {
class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEntityStorageInterface, DynamicallyFieldableEntityStorageSchemaInterface, EntityBundleListenerInterface {
/**
* The mapping of field columns to SQL tables.
......@@ -605,9 +606,7 @@ protected function mapFromStorageRecords(array $records) {
$this->attachPropertyData($entities);
// Attach field values.
if ($this->entityType->isFieldable()) {
$this->loadFieldItems($entities);
}
$this->loadFieldItems($entities);
return $entities;
}
......@@ -1180,7 +1179,7 @@ public function getQueryServiceName() {
* An array of entities keyed by entity ID.
*/
protected function loadFieldItems(array $entities) {
if (empty($entities) || !$this->entityType->isFieldable()) {
if (empty($entities)) {
return;
}
......@@ -1546,7 +1545,17 @@ public function onFieldDefinitionDelete(FieldDefinitionInterface $field_definiti
/**
* {@inheritdoc}
*/
public function onBundleRename($bundle, $bundle_new) {
public function onBundleCreate($bundle, $entity_type_id) { }
/**
* {@inheritdoc}
*/
public function onBundleDelete($bundle, $entity_type_id) { }
/**
* {@inheritdoc}
*/
public function onBundleRename($bundle, $bundle_new, $entity_type_id) {
// The method runs before the field definitions are updated, so we use the
// old bundle name.
$field_definitions = $this->entityManager->getFieldDefinitions($this->entityTypeId, $bundle);
......
......@@ -14,7 +14,7 @@
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException;
use Drupal\Core\Entity\Schema\FieldableEntityStorageSchemaInterface;
use Drupal\Core\Entity\Schema\DynamicallyFieldableEntityStorageSchemaInterface;
use Drupal\Core\Field\FieldException;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\FieldStorageConfigInterface;
......@@ -27,7 +27,7 @@
* optimizations and getSharedTableFieldSchema() for optimizations applying to
* a single field.
*/
class SqlContentEntityStorageSchema implements FieldableEntityStorageSchemaInterface {
class SqlContentEntityStorageSchema implements DynamicallyFieldableEntityStorageSchemaInterface {
/**
* The entity manager.
......
......@@ -944,7 +944,7 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
foreach ($entity_manager->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type->getProvider() == $module) {
foreach (array_keys($entity_manager->getBundleInfo($entity_type_id)) as $bundle) {
$entity_manager->onBundleDelete($entity_type_id, $bundle);
$entity_manager->onBundleDelete($bundle, $entity_type_id);
}
}
}
......
......@@ -39,7 +39,6 @@
* },
* field_ui_base_route = "aggregator.admin_overview",
* base_table = "aggregator_feed",
* fieldable = TRUE,
* render_cache = FALSE,
* entity_keys = {
* "id" = "fid",
......
......@@ -30,7 +30,6 @@
* },
* uri_callback = "Drupal\aggregator\Entity\Item::buildUri",
* base_table = "aggregator_item",
* fieldable = TRUE,
* render_cache = FALSE,
* entity_keys = {
* "id" = "iid",
......
......@@ -31,7 +31,6 @@
* }
* },
* admin_permission = "administer blocks",
* fieldable = FALSE,
* entity_keys = {
* "id" = "id"
* },
......
......@@ -43,7 +43,6 @@
* "delete-form" = "entity.block_content.delete_form",
* "edit-form" = "entity.block_content.canonical",
* },
* fieldable = TRUE,
* translatable = TRUE,
* entity_keys = {
* "id" = "id",
......
......@@ -412,7 +412,7 @@ function comment_entity_predelete(EntityInterface $entity) {
// mismatched types. So, we need to verify that the ID is numeric (even for an
// entity type that has an integer ID, $entity->id() might be a string
// containing a number), and then cast it to an integer when querying.
if ($entity->getEntityType()->isFieldable() && is_numeric($entity->id())) {
if ($entity instanceof ContentEntityInterface && is_numeric($entity->id())) {
$entity_query = \Drupal::entityQuery('comment');
$entity_query->condition('entity_id', (int) $entity->id());
$entity_query->condition('entity_type', $entity->getEntityTypeId());
......
......@@ -22,7 +22,7 @@ function comment_views_data_alter(&$data) {
// Provide a integration for each entity type except comment.
foreach (\Drupal::entityManager()->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type_id == 'comment' || !$entity_type->isFieldable() || !$entity_type->getBaseTable()) {
if ($entity_type_id == 'comment' || !$entity_type->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface') || !$entity_type->getBaseTable()) {
continue;
}
$fields = \Drupal::service('comment.manager')->getFields($entity_type_id);
......
......@@ -7,6 +7,7 @@
namespace Drupal\comment;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
......@@ -91,7 +92,9 @@ public function form(array $form, FormStateInterface $form_state) {
if ($comment_type->isNew()) {
$options = array();
foreach ($this->entityManager->getDefinitions() as $entity_type) {
if ($entity_type->isFieldable()) {
// Only expose entities that have field UI enabled, only those can
// get comment fields added in the UI.
if ($entity_type->get('field_ui_base_route')) {
$options[$entity_type->id()] = $entity_type->getLabel();
}
}
......
......@@ -386,7 +386,7 @@ public function getViewsData() {
// Provide a relationship for each entity type except comment.
foreach ($entities_types as $type => $entity_type) {
if ($type == 'comment' || !$entity_type->isFieldable() || !$entity_type->getBaseTable()) {
if ($type == 'comment' || !$entity_type->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface') || !$entity_type->getBaseTable()) {
continue;
}
if ($fields = \Drupal::service('comment.manager')->getFields($type)) {
......@@ -465,7 +465,7 @@ public function getViewsData() {
// Provide a relationship for each entity type except comment.
foreach ($entities_types as $type => $entity_type) {
if ($type == 'comment' || !$entity_type->isFieldable() || !$entity_type->getBaseTable()) {
if ($type == 'comment' || !$entity_type->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface') || !$entity_type->getBaseTable()) {
continue;
}
// This relationship does not use the 'field id' column, if the entity has
......
......@@ -38,7 +38,6 @@
* base_table = "comment",
* data_table = "comment_field_data",
* uri_callback = "comment_uri",
* fieldable = TRUE,
* translatable = TRUE,
* entity_keys = {
* "id" = "cid",
......
......@@ -48,8 +48,8 @@ function hook_config_translation_info(&$info) {
// Ignore non-existent routes.
}
// Make sure entity type is fieldable and has a base route.
if ($entity_type->isFieldable() && !empty($base_route)) {
// Make sure entity type has field UI enabled and has a base route.
if ($entity_type->get('field_ui_base_route') && !empty($base_route)) {
$info[$entity_type_id . '_fields'] = array(
'base_route_name' => 'field_ui.field_edit_' . $entity_type_id,
'entity_type' => 'field_config',
......
......@@ -120,8 +120,8 @@ function config_translation_config_translation_info(&$info) {
// Ignore non-existent routes.
}
// Make sure entity type is fieldable and has a base route.
if ($entity_type->isFieldable() && !empty($base_route)) {
// Make sure entity type has field UI enabled and has a base route.
if ($entity_type->get('field_ui_base_route') && !empty($base_route)) {
$info[$entity_type_id . '_fields'] = array(
'base_route_name' => 'field_ui.field_edit_' . $entity_type_id,
'entity_type' => 'field_config',
......
......@@ -31,7 +31,6 @@
* },
* bundle_entity_type = "contact_form",
* field_ui_base_route = "entity.contact_form.edit_form",
* fieldable = TRUE,
* )
*/
class Message extends ContentEntityBase implements MessageInterface {
......
......@@ -173,31 +173,28 @@ protected function enableTranslation() {
* Creates the test fields.
*/
protected function setupTestFields() {
$entity_type = \Drupal::entityManager()->getDefinition($this->entityTypeId);
if ($entity_type->isFieldable()) {
if (empty($this->fieldName)) {
$this->fieldName = 'field_test_et_ui_test';
}
entity_create('field_storage_config', array(
'field_name' => $this->fieldName,
'type' => 'string',
'entity_type' => $this->entityTypeId,
'cardinality' => 1,
'translatable' => TRUE,
))->save();
entity_create('field_config', array(
'entity_type' => $this->entityTypeId,
'field_name' => $this->fieldName,
'bundle' => $this->bundle,
'label' => 'Test translatable text-field',
))->save();
entity_get_form_display($this->entityTypeId, $this->bundle, 'default')
->setComponent($this->fieldName, array(
'type' => 'string_textfield',
'weight' => 0,
))
->save();
if (empty($this->fieldName)) {
$this->fieldName = 'field_test_et_ui_test';
}
entity_create('field_storage_config', array(
'field_name' => $this->fieldName,
'type' => 'string',
'entity_type' => $this->entityTypeId,
'cardinality' => 1,
'translatable' => TRUE,
))->save();
entity_create('field_config', array(
'entity_type' => $this->entityTypeId,
'field_name' => $this->fieldName,
'bundle' => $this->bundle,
'label' => 'Test translatable text-field',
))->save();
entity_get_form_display($this->entityTypeId, $this->bundle, 'default')
->setComponent($this->fieldName, array(
'type' => 'string_textfield',
'weight' => 0,
))
->save();
}
/**
......
<
......@@ -6,6 +6,7 @@
use Drupal\Core\Config\ConfigImporter;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\DynamicallyFieldableEntityStorageInterface;
use Drupal\Core\Extension\Extension;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
......@@ -152,20 +153,19 @@ function field_system_info_alter(&$info, Extension $file, $type) {
* Implements hook_entity_field_storage_info().
*/
function field_entity_field_storage_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type) {
// Expose storage definitions for all exposed bundle fields.
if ($entity_type->isFieldable()) {
if (\Drupal::entityManager()->getStorage($entity_type->id()) instanceof DynamicallyFieldableEntityStorageInterface) {
// Query by filtering on the ID as this is more efficient than filtering
// on the entity_type property directly.
$ids = \Drupal::entityQuery('field_storage_config')
->condition('id', $entity_type->id() . '.', 'STARTS_WITH')
->execute();
// Fetch all fields and key them by field name.
$field_storages = entity_load_multiple('field_storage_config', $ids);
$result = array();
foreach ($field_storages as $field_storage) {
$result[$field_storage->getName()] = $field_storage;
}
return $result;
}
}
......@@ -174,19 +174,19 @@ function field_entity_field_storage_info(\Drupal\Core\Entity\EntityTypeInterface
* Implements hook_entity_bundle_field_info().
*/