diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php index 2f37596..3f28a78 100644 --- a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php @@ -450,7 +450,10 @@ public function onDependencyRemoval(array $dependencies) { if ($renderer->onDependencyRemoval($component_removed_dependencies)) { // Update component settings to reflect changes. $component['settings'] = $renderer->getSettings(); - $component['third_party_settings'] = $renderer->getThirdPartySettings(); + $component['third_party_settings'] = []; + foreach ($renderer->getThirdPartyProviders() as $module) { + $component['third_party_settings'][$module] = $renderer->getThirdPartySettings($module); + } $this->setComponent($name, $component); $changed = TRUE; } @@ -497,11 +500,16 @@ protected function getPluginRemovedDependencies(array $plugin_dependencies, arra $intersect = []; foreach ($plugin_dependencies as $type => $dependencies) { if ($removed_dependencies[$type]) { - $is_entity_dependency = in_array($type, ['config', 'content']); // Config and content entities have the dependency names as keys while // module and theme dependencies are indexed arrays of dependency names. // @see \Drupal\Core\Config\ConfigManager::callOnDependencyRemoval() - if ($removed = $is_entity_dependency ? array_intersect_key($removed_dependencies[$type], array_flip($dependencies)) : array_values(array_intersect($removed_dependencies[$type], $dependencies))) { + if (in_array($type, ['config', 'content'])) { + $removed = array_intersect_key($removed_dependencies[$type], array_flip($dependencies)); + } + else { + $removed = array_values(array_intersect($removed_dependencies[$type], $dependencies)); + } + if ($removed) { $intersect[$type] = $removed; } } diff --git a/core/lib/Drupal/Core/Field/PluginSettingsBase.php b/core/lib/Drupal/Core/Field/PluginSettingsBase.php index 7d63348..c61d96f 100644 --- a/core/lib/Drupal/Core/Field/PluginSettingsBase.php +++ b/core/lib/Drupal/Core/Field/PluginSettingsBase.php @@ -122,6 +122,26 @@ public function setThirdPartySetting($module, $key, $value) { /** * {@inheritdoc} */ + public function unsetThirdPartySetting($module, $key) { + unset($this->thirdPartySettings[$module][$key]); + // If the third party is no longer storing any information, completely + // remove the array holding the settings for this module. + if (empty($this->thirdPartySettings[$module])) { + unset($this->thirdPartySettings[$module]); + } + return $this; + } + + /** + * {@inheritdoc} + */ + public function getThirdPartyProviders() { + return array_keys($this->thirdPartySettings); + } + + /** + * {@inheritdoc} + */ public function calculateDependencies() { if (!empty($this->thirdPartySettings)) { // Create dependencies on any modules providing third party settings. diff --git a/core/lib/Drupal/Core/Field/PluginSettingsInterface.php b/core/lib/Drupal/Core/Field/PluginSettingsInterface.php index 5638a7c..8ee2ac5 100644 --- a/core/lib/Drupal/Core/Field/PluginSettingsInterface.php +++ b/core/lib/Drupal/Core/Field/PluginSettingsInterface.php @@ -8,11 +8,12 @@ namespace Drupal\Core\Field; use Drupal\Component\Plugin\PluginInspectionInterface; +use Drupal\Core\Config\Entity\ThirdPartySettingsInterface; /** * Interface definition for plugin with settings. */ -interface PluginSettingsInterface extends PluginInspectionInterface { +interface PluginSettingsInterface extends PluginInspectionInterface, ThirdPartySettingsInterface { /** * Defines the default settings for this plugin. @@ -65,51 +66,6 @@ public function setSettings(array $settings); public function setSetting($key, $value); /** - * Returns the value of a third-party setting, or $default if not set. - * - * @param string $module - * The module providing the third-party setting. - * @param string $key - * The setting name. - * @param mixed $default - * (optional) The default value if the third party setting is not set. - * Defaults to NULL. - * - * @return mixed|NULL - * The setting value. Returns NULL if the setting does not exist and - * $default is not provided. - */ - public function getThirdPartySetting($module, $key, $default = NULL); - - /** - * Returns all third-party settings values. - * - * @param string|null $module - * (optional) If passed, only settings provided by that module will be - * returned. If omitted all settings will be returned. Defaults to NULL. - * - * @return array|null - * All third-party settings, if the module is omitted. Only settings - * provided by the module, if a module is passed. If a module has been - * passed but that module has no settings, NULL will be returned. - */ - public function getThirdPartySettings($module = NULL); - - /** - * Sets the value of a third-party setting for the plugin. - * - * @param string $module - * The module providing the third-party setting. - * @param string $key - * The setting name. - * @param mixed $value - * The setting value. - * - * @return $this - */ - public function setThirdPartySetting($module, $key, $value); - - /** * Informs the plugin that some configuration it depends on will be deleted. * * This method allows plugins to keep their configuration up-to-date when a