diff --git a/core/lib/Drupal/Core/Block/Plugin/Block/Broken.php b/core/lib/Drupal/Core/Block/Plugin/Block/Broken.php index df61f3b..429b6f0 100644 --- a/core/lib/Drupal/Core/Block/Plugin/Block/Broken.php +++ b/core/lib/Drupal/Core/Block/Plugin/Block/Broken.php @@ -49,4 +49,14 @@ protected function brokenMessage() { return $build; } + /** + * {@inheritdoc} + */ + public function calculateDependencies() { + // Broken blocks should preserve the provider of the broken plugin. + $dependencies = parent::calculateDependencies(); + $dependencies['module'][] = $this->configuration['provider']; + return $dependencies; + } + } diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index bb396e6..f235b04 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -352,9 +352,13 @@ public function preSave(EntityStorageInterface $storage) { * {@inheritdoc} */ public function calculateDependencies() { - // All dependencies should be recalculated on every save apart from enforced - // dependencies. This ensures stale dependencies are never saved. - $this->dependencies = array_intersect_key($this->dependencies, ['enforced' => '']); + // Content dependencies are preserved because they are soft and the content + // might not exist when the configuration entity is created. This can be the + // case during configuration sync. Enforced dependencies are preserved + // because this is the only place this information exists. Recalculating + // configuration and module dependencies ensures stale information is never + // saved. + $this->dependencies = array_intersect_key($this->dependencies, ['enforced' => '', 'content' => '']); if ($this instanceof EntityWithPluginCollectionInterface) { // Configuration entities need to depend on the providers of any plugins // that they store the configuration for. diff --git a/core/modules/block_content/tests/modules/block_content_test/config/install/block.block.test_content_dependency.yml b/core/modules/block_content/tests/modules/block_content_test/config/install/block.block.test_content_dependency.yml new file mode 100644 index 0000000..a44a340 --- /dev/null +++ b/core/modules/block_content/tests/modules/block_content_test/config/install/block.block.test_content_dependency.yml @@ -0,0 +1,24 @@ +langcode: en +status: true +dependencies: + content: + - 'block_content:basic:7297c945-457f-4b2c-8700-dc3052ab63ba' + module: + - block_content + theme: + - classy +id: test_content_dependency +theme: classy +region: content +weight: -8 +provider: null +plugin: 'block_content:7297c945-457f-4b2c-8700-dc3052ab63ba' +settings: + id: 'block_content:7297c945-457f-4b2c-8700-dc3052ab63ba' + label: 'Test Block' + provider: block_content + label_display: visible + status: true + info: '' + view_mode: full +visibility: { } diff --git a/core/modules/block_content/tests/src/Kernel/BlockContentDependencyTest.php b/core/modules/block_content/tests/src/Kernel/BlockContentDependencyTest.php new file mode 100644 index 0000000..eb370ea --- /dev/null +++ b/core/modules/block_content/tests/src/Kernel/BlockContentDependencyTest.php @@ -0,0 +1,61 @@ +installEntitySchema('block_content'); + $this->installEntitySchema('block'); + $this->installConfig(['block_content_test']); + + BlockContent::create([ + 'uuid' => '7297c945-457f-4b2c-8700-dc3052ab63ba', + 'type' => 'basic', + ])->save(); + } + + /** + * Test that dependencies are not removed upon import. + */ + public function testBlockContentDependency() { + $config_name = 'block.block.test_content_dependency'; + $default_install_path = drupal_get_path('module', 'block_content_test') . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY; + $module_config_storage = new FileStorage($default_install_path, StorageInterface::DEFAULT_COLLECTION); + + $result = $this->container->get('config.manager') + ->diff($module_config_storage, $this->container->get('config.storage'), $config_name); + $this->assertConfigDiff($result, $config_name, []); + } + +} diff --git a/core/modules/field/src/Tests/EntityReference/EntityReferenceIntegrationTest.php b/core/modules/field/src/Tests/EntityReference/EntityReferenceIntegrationTest.php index 4d678f8..c4ffe7d 100644 --- a/core/modules/field/src/Tests/EntityReference/EntityReferenceIntegrationTest.php +++ b/core/modules/field/src/Tests/EntityReference/EntityReferenceIntegrationTest.php @@ -164,7 +164,14 @@ public function testSupportedEntityTypesAndWidgets() { $field = FieldConfig::loadByName($this->entityType, $this->bundle, $this->fieldName); $field->save(); $dependencies = $field->getDependencies(); - $this->assertFalse(isset($dependencies[$key]) && in_array($referenced_entities[0]->getConfigDependencyName(), $dependencies[$key]), SafeMarkup::format('@type dependency @name does not exist.', ['@type' => $key, '@name' => $referenced_entities[0]->getConfigDependencyName()])); + // Content dependencies are soft and therefore will not be removed if they + // do not exist. + if ($key !== 'content') { + $this->assertFalse(isset($dependencies[$key]) && in_array($referenced_entities[0]->getConfigDependencyName(), $dependencies[$key]), SafeMarkup::format('@type dependency @name does not exist.', [ + '@type' => $key, + '@name' => $referenced_entities[0]->getConfigDependencyName() + ])); + } } } diff --git a/core/modules/views/src/Tests/Entity/ViewEntityDependenciesTest.php b/core/modules/views/src/Tests/Entity/ViewEntityDependenciesTest.php index 632be6a..6270175 100644 --- a/core/modules/views/src/Tests/Entity/ViewEntityDependenciesTest.php +++ b/core/modules/views/src/Tests/Entity/ViewEntityDependenciesTest.php @@ -103,15 +103,15 @@ public function testGetDependencies() { ] ]; $expected['test_plugin_dependencies'] = [ - 'module' => [ - 'comment', - 'views_test_data', - ], 'content' => [ 'RowTest', 'StaticTest', 'StyleTest', - ] + ], + 'module' => [ + 'comment', + 'views_test_data', + ], ]; $expected['test_argument_dependency'] = [ diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_plugin_dependencies.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_plugin_dependencies.yml index 21877c9..4a123e6 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_plugin_dependencies.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_plugin_dependencies.yml @@ -5,8 +5,8 @@ dependencies: - comment - views_test_data content: - - StaticTest - RowTest + - StaticTest - StyleTest id: test_plugin_dependencies label: test_plugin_dependencies