From 3bc319745ce6fc033c65661ed1b1e4cfcbbee648 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Tue, 14 Apr 2015 09:28:14 +0200 Subject: [PATCH] Issue #2079427 by Berdir, andypost, yched: Core/Entity depends on classes / functions from field.module --- .../Core/Entity/Entity/EntityFormDisplay.php | 2 +- .../Core/Entity/Entity/EntityViewDisplay.php | 2 +- .../Drupal/Core/Entity/EntityDisplayBase.php | 23 +++++++++++-------- .../Core/Field/Annotation/FieldWidget.php | 2 +- .../Drupal/Core/Field/FieldItemInterface.php | 8 +++---- .../src/Entity/ConfigQueryTest.php | 2 +- .../Tests/ContentTestTranslationUITest.php | 2 +- .../ContentTranslationEntityBundleUITest.php | 2 +- .../Tests/ContentTranslationSyncImageTest.php | 2 +- .../Tests/ContentTranslationSyncUnitTest.php | 2 +- .../src/Tests/ContentTranslationTestBase.php | 2 +- .../src/Tests/ContentTranslationUITest.php | 2 +- .../Tests/ContentTranslationWorkflowsTest.php | 2 +- .../src/Access/FormModeAccessCheck.php | 2 +- .../src/Access/ViewModeAccessCheck.php | 2 +- .../src/EntityDisplayModeListBuilder.php | 2 +- .../src/EntityFormModeListBuilder.php | 2 +- .../field_ui/src/Tests/EntityDisplayTest.php | 2 +- .../src/Tests/EntityFormDisplayTest.php | 2 +- .../modules/entity_test/entity_test.module | 2 +- 20 files changed, 36 insertions(+), 31 deletions(-) diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php index dfe912e545c5..882286ad9040 100644 --- a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php +++ b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php @@ -192,7 +192,7 @@ public function buildForm(FieldableEntityInterface $entity, array &$form, FormSt /** * Process callback: assigns weights and hides extra fields. * - * @see \Drupal\entity\Entity\EntityFormDisplay::buildForm() + * @see \Drupal\Core\Entity\Entity\EntityFormDisplay::buildForm() */ public function processForm($element, FormStateInterface $form_state, $form) { // Assign the weights configured in the form display. diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php index 79c0f13d72e0..efffdbc03e6c 100644 --- a/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php +++ b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php @@ -152,7 +152,7 @@ public static function collectRenderDisplays($entities, $view_mode) { * @return \Drupal\Core\Entity\Display\EntityViewDisplayInterface * The display object that should be used to render the entity. * - * @see \Drupal\entity\Entity\EntityDisplay::collectRenderDisplays() + * @see \Drupal\Core\Entity\Entity\EntityViewDisplay::collectRenderDisplays() */ public static function collectRenderDisplay(FieldableEntityInterface $entity, $view_mode) { $displays = static::collectRenderDisplays(array($entity), $view_mode); diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php index 96fa0de94cd7..39e953fb8777 100644 --- a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php @@ -8,10 +8,9 @@ namespace Drupal\Core\Entity; use Drupal\Core\Config\Entity\ConfigEntityBase; +use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Entity\Display\EntityDisplayInterface; -use Drupal\field\Entity\FieldConfig; -use Drupal\field\FieldConfigInterface; use Drupal\Component\Utility\SafeMarkup; /** @@ -262,14 +261,20 @@ public function calculateDependencies() { // Depend on the provider of the entity type. $this->addDependency('module', $target_entity_type->getProvider()); } - // Create dependencies on both hidden and visible fields. - $fields = $this->content + $this->hidden; - foreach ($fields as $field_name => $component) { - $field = FieldConfig::loadByName($this->targetEntityType, $this->bundle, $field_name); - if ($field) { - $this->addDependency('config', $field->getConfigDependencyName()); + + // If field.module is enabled, add dependencies on 'field_config' entities + // for both displayed and hidden fields. We intentionally leave out base + // field overrides, since the field still exists without them. + if (\Drupal::moduleHandler()->moduleExists('field')) { + $components = $this->content + $this->hidden; + $field_definitions = $this->entityManager()->getFieldDefinitions($this->targetEntityType, $this->bundle); + foreach (array_intersect_key($field_definitions, $components) as $field_name => $field_definition) { + if ($field_definition instanceof ConfigEntityInterface && $field_definition->getEntityTypeId() == 'field_config') { + $this->addDependency('config', $field_definition->getConfigDependencyName()); + } } } + // Depend on configured modes. if ($this->mode != 'default') { $mode_entity = $this->entityManager()->getStorage('entity_' . $this->displayContext . '_mode')->load($target_entity_type->id() . '.' . $this->mode); @@ -417,7 +422,7 @@ private function fieldHasDisplayOptions(FieldDefinitionInterface $definition) { public function onDependencyRemoval(array $dependencies) { $changed = parent::onDependencyRemoval($dependencies); foreach ($dependencies['config'] as $entity) { - if ($entity instanceof FieldConfigInterface) { + if ($entity->getEntityTypeId() == 'field_config') { // Remove components for fields that are being deleted. $this->removeComponent($entity->getName()); unset($this->hidden[$entity->getName()]); diff --git a/core/lib/Drupal/Core/Field/Annotation/FieldWidget.php b/core/lib/Drupal/Core/Field/Annotation/FieldWidget.php index 542ed0b37fec..5ca352edaa2c 100644 --- a/core/lib/Drupal/Core/Field/Annotation/FieldWidget.php +++ b/core/lib/Drupal/Core/Field/Annotation/FieldWidget.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\field\Annotation\FieldWidget. + * Contains \Drupal\Core\Field\Annotation\FieldWidget. */ namespace Drupal\Core\Field\Annotation; diff --git a/core/lib/Drupal/Core/Field/FieldItemInterface.php b/core/lib/Drupal/Core/Field/FieldItemInterface.php index 2479ca3f30fc..a2339acacb0c 100644 --- a/core/lib/Drupal/Core/Field/FieldItemInterface.php +++ b/core/lib/Drupal/Core/Field/FieldItemInterface.php @@ -80,10 +80,10 @@ public static function mainPropertyName(); * Only columns that appear in the 'columns' array are allowed. * - indexes: (optional) An array of Schema API index definitions. Only * columns that appear in the 'columns' array are allowed. Those indexes - * will be used as default indexes. Callers of field_create_field() can - * specify additional indexes or, at their own risk, modify the default - * indexes specified by the field-type module. Some storage engines might - * not support indexes. + * will be used as default indexes. Field definitions can specify + * additional indexes or, at their own risk, modify the default indexes + * specified by the field-type module. Some storage engines might not + * support indexes. * - 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 diff --git a/core/modules/config/tests/config_test/src/Entity/ConfigQueryTest.php b/core/modules/config/tests/config_test/src/Entity/ConfigQueryTest.php index 022b1f1360fb..062124439631 100644 --- a/core/modules/config/tests/config_test/src/Entity/ConfigQueryTest.php +++ b/core/modules/config/tests/config_test/src/Entity/ConfigQueryTest.php @@ -27,7 +27,7 @@ * } * ) * - * @see \Drupal\entity\Tests\ConfigEntityQueryTest + * @see \Drupal\system\Tests\Entity\ConfigEntityQueryTest */ class ConfigQueryTest extends ConfigTest { diff --git a/core/modules/content_translation/src/Tests/ContentTestTranslationUITest.php b/core/modules/content_translation/src/Tests/ContentTestTranslationUITest.php index aa499159c718..0db24c8b704d 100644 --- a/core/modules/content_translation/src/Tests/ContentTestTranslationUITest.php +++ b/core/modules/content_translation/src/Tests/ContentTestTranslationUITest.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\entity\Tests\ContentTestTranslationUITest. + * Contains \Drupal\content_translation\Tests\ContentTestTranslationUITest. */ namespace Drupal\content_translation\Tests; diff --git a/core/modules/content_translation/src/Tests/ContentTranslationEntityBundleUITest.php b/core/modules/content_translation/src/Tests/ContentTranslationEntityBundleUITest.php index 5a1ac836d91a..2c432c4c3781 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationEntityBundleUITest.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationEntityBundleUITest.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\entity\Tests\ContentTranslationEntityBundleUITest. + * Contains \Drupal\content_translation\Tests\ContentTranslationEntityBundleUITest. */ namespace Drupal\content_translation\Tests; diff --git a/core/modules/content_translation/src/Tests/ContentTranslationSyncImageTest.php b/core/modules/content_translation/src/Tests/ContentTranslationSyncImageTest.php index f1b7688a5fb2..606b5b34c14a 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationSyncImageTest.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationSyncImageTest.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\entity\Tests\ContentTranslationSyncImageTest. + * Contains \Drupal\content_translation\Tests\ContentTranslationSyncImageTest. */ namespace Drupal\content_translation\Tests; diff --git a/core/modules/content_translation/src/Tests/ContentTranslationSyncUnitTest.php b/core/modules/content_translation/src/Tests/ContentTranslationSyncUnitTest.php index a15977a88bea..53c5b0ac2f8a 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationSyncUnitTest.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationSyncUnitTest.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\entity\Tests\ContentTranslationSyncUnitTest. + * Contains \Drupal\content_translation\Tests\ContentTranslationSyncUnitTest. */ namespace Drupal\content_translation\Tests; diff --git a/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php b/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php index a9d2c5ba40ba..d00b3789a29a 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\entity\Tests\ContentTranslationTestBase. + * Contains \Drupal\content_translation\Tests\ContentTranslationTestBase. */ namespace Drupal\content_translation\Tests; diff --git a/core/modules/content_translation/src/Tests/ContentTranslationUITest.php b/core/modules/content_translation/src/Tests/ContentTranslationUITest.php index 0ec3280b3224..5a7429cafd24 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationUITest.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationUITest.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\entity\Tests\ContentTranslationUITest. + * Contains \Drupal\content_translation\Tests\ContentTranslationUITest. */ namespace Drupal\content_translation\Tests; diff --git a/core/modules/content_translation/src/Tests/ContentTranslationWorkflowsTest.php b/core/modules/content_translation/src/Tests/ContentTranslationWorkflowsTest.php index 76470a726564..62daf7557e01 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationWorkflowsTest.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationWorkflowsTest.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\entity\Tests\ContentTranslationWorkflowsTest. + * Contains \Drupal\content_translation\Tests\ContentTranslationWorkflowsTest. */ namespace Drupal\content_translation\Tests; diff --git a/core/modules/field_ui/src/Access/FormModeAccessCheck.php b/core/modules/field_ui/src/Access/FormModeAccessCheck.php index 055f588b09bb..35c83f9efe02 100644 --- a/core/modules/field_ui/src/Access/FormModeAccessCheck.php +++ b/core/modules/field_ui/src/Access/FormModeAccessCheck.php @@ -17,7 +17,7 @@ /** * Defines an access check for entity form mode routes. * - * @see \Drupal\entity\Entity\EntityFormMode + * @see \Drupal\Core\Entity\Entity\EntityFormMode */ class FormModeAccessCheck implements AccessInterface { diff --git a/core/modules/field_ui/src/Access/ViewModeAccessCheck.php b/core/modules/field_ui/src/Access/ViewModeAccessCheck.php index a3e5e469a75b..6e764a383a2b 100644 --- a/core/modules/field_ui/src/Access/ViewModeAccessCheck.php +++ b/core/modules/field_ui/src/Access/ViewModeAccessCheck.php @@ -17,7 +17,7 @@ /** * Defines an access check for entity view mode routes. * - * @see \Drupal\entity\Entity\EntityViewMode + * @see \Drupal\Core\Entity\Entity\EntityViewMode */ class ViewModeAccessCheck implements AccessInterface { diff --git a/core/modules/field_ui/src/EntityDisplayModeListBuilder.php b/core/modules/field_ui/src/EntityDisplayModeListBuilder.php index 6dc915438386..f17a07669dc3 100644 --- a/core/modules/field_ui/src/EntityDisplayModeListBuilder.php +++ b/core/modules/field_ui/src/EntityDisplayModeListBuilder.php @@ -17,7 +17,7 @@ /** * Defines a class to build a listing of view mode entities. * - * @see \Drupal\entity\Entity\EntityViewMode + * @see \Drupal\Core\Entity\Entity\EntityViewMode */ class EntityDisplayModeListBuilder extends ConfigEntityListBuilder { diff --git a/core/modules/field_ui/src/EntityFormModeListBuilder.php b/core/modules/field_ui/src/EntityFormModeListBuilder.php index 8515265647f3..f6fc24b47fc9 100644 --- a/core/modules/field_ui/src/EntityFormModeListBuilder.php +++ b/core/modules/field_ui/src/EntityFormModeListBuilder.php @@ -10,7 +10,7 @@ /** * Defines a class to build a listing of form mode entities. * - * @see \Drupal\entity\Entity\EntityFormMode + * @see \Drupal\Core\Entity\Entity\EntityFormMode */ class EntityFormModeListBuilder extends EntityDisplayModeListBuilder { diff --git a/core/modules/field_ui/src/Tests/EntityDisplayTest.php b/core/modules/field_ui/src/Tests/EntityDisplayTest.php index 05f2cc4d173f..495b8e778540 100644 --- a/core/modules/field_ui/src/Tests/EntityDisplayTest.php +++ b/core/modules/field_ui/src/Tests/EntityDisplayTest.php @@ -391,7 +391,7 @@ public function testDeleteField() { } /** - * Tests \Drupal\entity\EntityDisplayBase::onDependencyRemoval(). + * Tests \Drupal\Core\Entity\EntityDisplayBase::onDependencyRemoval(). */ public function testOnDependencyRemoval() { $this->enableModules(array('field_plugins_test')); diff --git a/core/modules/field_ui/src/Tests/EntityFormDisplayTest.php b/core/modules/field_ui/src/Tests/EntityFormDisplayTest.php index 6e84b95c610c..1e5ac237b4c1 100644 --- a/core/modules/field_ui/src/Tests/EntityFormDisplayTest.php +++ b/core/modules/field_ui/src/Tests/EntityFormDisplayTest.php @@ -224,7 +224,7 @@ public function testDeleteField() { } /** - * Tests \Drupal\entity\EntityDisplayBase::onDependencyRemoval(). + * Tests \Drupal\Core\Entity\EntityDisplayBase::onDependencyRemoval(). */ public function testOnDependencyRemoval() { $this->enableModules(array('field_plugins_test')); diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index a084b130cd90..164a7c0ac846 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -236,7 +236,7 @@ function entity_test_entity_extra_field_info() { $extra['entity_test']['bundle_with_extra_fields'] = array( 'display' => array( // Note: those extra fields do not currently display anything, they are - // just used in \Drupal\entity\Tests\EntityDisplayTest to test the + // just used in \Drupal\field_ui\Tests\EntityDisplayTest to test the // behavior of entity display objects. 'display_extra_field' => array( 'label' => t('Display extra field'), -- GitLab