diff --git a/core/lib/Drupal/Core/Config/ConfigManager.php b/core/lib/Drupal/Core/Config/ConfigManager.php index e3fcaf8..827f9ef 100644 --- a/core/lib/Drupal/Core/Config/ConfigManager.php +++ b/core/lib/Drupal/Core/Config/ConfigManager.php @@ -221,7 +221,9 @@ public function uninstall($type, $name) { $affected_dependencies[$type] = array($name); } // Inform the entity. - $entity->onDependencyRemoval($affected_dependencies); + if ($entity->onDependencyRemoval($affected_dependencies)) { + $entity->save(); + } } // Recalculate the dependencies, some config entities may have fixed their diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index b587f63..0f21a02 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -24,7 +24,7 @@ * * @ingroup entity_api */ -abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface { +abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface, ThirdPartySettingsInterface { use PluginDependencyTrait { addDependency as addDependencyTrait; @@ -435,6 +435,13 @@ public function getConfigTarget() { * {@inheritdoc} */ public function onDependencyRemoval(array $dependencies) { + $changed = FALSE; + if (!empty($this->third_party_settings)) { + $old_count = count($this->third_party_settings); + $this->third_party_settings = array_diff_key($this->third_party_settings, array_flip($dependencies['module'])); + $changed = $old_count != count($this->third_party_settings); + } + return $changed; } /** diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php index 15347e3..2a59b39 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php @@ -170,6 +170,9 @@ public function calculateDependencies(); * An array of dependencies that will be deleted keyed by dependency type. * Dependency types are, for example, entity, module and theme. * + * @return bool + * TRUE if the entity has changed, FALSE if not. + * * @see \Drupal\Core\Config\Entity\ConfigDependencyManager * @see \Drupal\Core\Config\ConfigManager::uninstall() * @see \Drupal\Core\Entity\EntityDisplayBase::onDependencyRemoval() diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php index 225d407..98e587b 100644 --- a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php @@ -421,7 +421,7 @@ private function fieldHasDisplayOptions(FieldDefinitionInterface $definition) { * {@inheritdoc} */ public function onDependencyRemoval(array $dependencies) { - $changed = FALSE; + $changed = parent::onDependencyRemoval($dependencies); foreach ($dependencies['config'] as $entity) { if ($entity instanceof FieldConfigInterface) { // Remove components for fields that are being deleted. @@ -440,9 +440,7 @@ public function onDependencyRemoval(array $dependencies) { } } } - if ($changed) { - $this->save(); - } + return $changed; } /** diff --git a/core/modules/config/tests/config_test/src/Entity/ConfigTest.php b/core/modules/config/tests/config_test/src/Entity/ConfigTest.php index 4357597..d1c9a57 100644 --- a/core/modules/config/tests/config_test/src/Entity/ConfigTest.php +++ b/core/modules/config/tests/config_test/src/Entity/ConfigTest.php @@ -122,7 +122,7 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti * {@inheritdoc} */ public function onDependencyRemoval(array $dependencies) { - $changed = FALSE; + $changed = parent::onDependencyRemoval($dependencies); $fix_deps = \Drupal::state()->get('config_test.fix_dependencies', array()); foreach ($dependencies['config'] as $entity) { if (in_array($entity->getConfigDependencyName(), $fix_deps)) { @@ -133,9 +133,7 @@ public function onDependencyRemoval(array $dependencies) { } } } - if ($changed) { - $this->save(); - } + return $changed; } /** diff --git a/core/modules/content_translation/config/schema/content_translation.schema.yml b/core/modules/content_translation/config/schema/content_translation.schema.yml index ee2af64..ddccb5b 100644 --- a/core/modules/content_translation/config/schema/content_translation.schema.yml +++ b/core/modules/content_translation/config/schema/content_translation.schema.yml @@ -11,7 +11,7 @@ field.field.*.*.*.third_party.content_translation: - type: string label: 'Field column for which to synchronize translations' -language.entity.*.third_party.content_translation: +language.content_settings.*.*.third_party.content_translation: type: mapping label: 'Content translation content settings' mapping: diff --git a/core/modules/filter/src/Entity/FilterFormat.php b/core/modules/filter/src/Entity/FilterFormat.php index dc4643a..6df0f97 100644 --- a/core/modules/filter/src/Entity/FilterFormat.php +++ b/core/modules/filter/src/Entity/FilterFormat.php @@ -400,7 +400,7 @@ public function removeFilter($instance_id) { * {@inheritdoc} */ public function onDependencyRemoval(array $dependencies) { - $changed = FALSE; + $changed = parent::onDependencyRemoval($dependencies); $filters = $this->filters(); foreach ($filters as $filter) { // Remove disabled filters, so that this FilterFormat config entity can @@ -410,9 +410,7 @@ public function onDependencyRemoval(array $dependencies) { $changed = TRUE; } } - if ($changed) { - $this->save(); - } + return $changed; } /** diff --git a/core/modules/image/tests/modules/image_module_test/config/schema/image_module_test.schema.yml b/core/modules/image/tests/modules/image_module_test/config/schema/image_module_test.schema.yml index b723878..b0e8ebf 100644 --- a/core/modules/image/tests/modules/image_module_test/config/schema/image_module_test.schema.yml +++ b/core/modules/image/tests/modules/image_module_test/config/schema/image_module_test.schema.yml @@ -1,4 +1,4 @@ -image_style.*.third_party.image_module_test: +image.style.*.third_party.image_module_test: type: mapping label: 'Schema for image_module_test module additions to image_style entity' mapping: diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php index 7af62e5..c3a04bf 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php @@ -293,12 +293,17 @@ public function providerCalculateDependenciesWithPluginCollections() { * @covers ::calculateDependencies */ public function testCalculateDependenciesWithThirdPartySettings() { - $this->entity = $this->getMockForAbstractClass('\Drupal\Tests\Core\Config\Entity\Fixtures\ConfigEntityBaseWithThirdPartySettings', array(array(), $this->entityTypeId)); + $this->entity = $this->getMockForAbstractClass('\Drupal\Core\Config\Entity\ConfigEntityBase', array(array(), $this->entityTypeId)); $this->entity->setThirdPartySetting('test_provider', 'test', 'test'); $this->entity->setThirdPartySetting('test_provider2', 'test', 'test'); $this->entity->setThirdPartySetting($this->provider, 'test', 'test'); $this->assertEquals(array('test_provider', 'test_provider2'), $this->entity->calculateDependencies()['module']); + $changed = $this->entity->onDependencyRemoval(['module' => ['test_provider2']]); + $this->assertTrue($changed, 'Calling onDependencyRemoval with an existing third party dependency provider returns TRUE.'); + $changed = $this->entity->onDependencyRemoval(['module' => ['test_provider3']]); + $this->assertFalse($changed, 'Calling onDependencyRemoval with a non-existing third party dependency provider returns FALSE.'); + $this->assertEquals(array('test_provider'), $this->entity->calculateDependencies()['module']); } /** diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/Fixtures/ConfigEntityBaseWithThirdPartySettings.php b/core/tests/Drupal/Tests/Core/Config/Entity/Fixtures/ConfigEntityBaseWithThirdPartySettings.php deleted file mode 100644 index 100999c..0000000 --- a/core/tests/Drupal/Tests/Core/Config/Entity/Fixtures/ConfigEntityBaseWithThirdPartySettings.php +++ /dev/null @@ -1,21 +0,0 @@ -