diff --git a/core/lib/Drupal/Core/Config/Entity/ThirdPartySettingsTrait.php b/core/lib/Drupal/Core/Config/Entity/ThirdPartySettingsTrait.php index b37367f..1942c9b 100644 --- a/core/lib/Drupal/Core/Config/Entity/ThirdPartySettingsTrait.php +++ b/core/lib/Drupal/Core/Config/Entity/ThirdPartySettingsTrait.php @@ -10,15 +10,23 @@ /** * Provides generic implementation of ThirdPartySettingsInterface. * - * The default property used to store third party settings is 'settings'. To - * override for a specific implement set $thirdPartySettingKey in the - * constructor. + * The name of the property used to store third party settings is + * 'third_party_settings'. You need to provide configuration schema for that + * setting to ensure it is persisted. See 'third_party_settings' defined on + * field_config_base and other 'field_config.third_party.*' types. * * @see \Drupal\Core\Config\Entity\ThirdPartySettingsInterface */ trait ThirdPartySettingsTrait { - protected $thirdPartySettingKey = 'third_party_settings'; + /** + * Third party entity settings. + * + * An array of key/value pairs keyed by provider. + * + * @var array + */ + protected $third_party_settings = array(); /** * Sets the value of a third-party setting. @@ -33,7 +41,7 @@ * @return $this */ public function setThirdPartySetting($module, $key, $value) { - $this->{$this->thirdPartySettingKey}[$module][$key] = $value; + $this->third_party_settings[$module][$key] = $value; return $this; } @@ -51,8 +59,8 @@ public function setThirdPartySetting($module, $key, $value) { * The value. */ public function getThirdPartySetting($module, $key, $default = NULL) { - if (isset($this->{$this->thirdPartySettingKey}[$module][$key])) { - return $this->{$this->thirdPartySettingKey}[$module][$key]; + if (isset($this->third_party_settings[$module][$key])) { + return $this->third_party_settings[$module][$key]; } else { return $default; @@ -71,11 +79,11 @@ public function getThirdPartySetting($module, $key, $default = NULL) { * The value. */ public function unsetThirdPartySetting($module, $key) { - unset($this->{$this->thirdPartySettingKey}[$module][$key]); + unset($this->third_party_settings[$module][$key]); // If the third party is no longer storing any information completely remove // the setting. - if (empty($this->{$this->thirdPartySettingKey}[$module])) { - unset($this->{$this->thirdPartySettingKey}[$module]); + if (empty($this->third_party_settings[$module])) { + unset($this->third_party_settings[$module]); } return $this; } @@ -87,7 +95,7 @@ public function unsetThirdPartySetting($module, $key) { * The list of third parties. */ public function getThirdPartyProviders() { - return array_keys($this->{$this->thirdPartySettingKey}); + return array_keys($this->third_party_settings); } } diff --git a/core/lib/Drupal/Core/Field/FieldConfigBase.php b/core/lib/Drupal/Core/Field/FieldConfigBase.php index 189b417..462f98b 100644 --- a/core/lib/Drupal/Core/Field/FieldConfigBase.php +++ b/core/lib/Drupal/Core/Field/FieldConfigBase.php @@ -99,15 +99,6 @@ public $settings = array(); /** - * Third party field-type specific settings. - * - * An arrays of key/value pairs keyed by provider. - * - * @var array - */ - protected $third_party_settings = array(); - - /** * Flag indicating whether the field is required. * * TRUE if a value for this field is required when used with this bundle, diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/Fixtures/ConfigEntityBaseWithThirdPartySettings.php b/core/tests/Drupal/Tests/Core/Config/Entity/Fixtures/ConfigEntityBaseWithThirdPartySettings.php index 9d5db7c..6834e63 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/Fixtures/ConfigEntityBaseWithThirdPartySettings.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/Fixtures/ConfigEntityBaseWithThirdPartySettings.php @@ -20,5 +20,4 @@ abstract class ConfigEntityBaseWithThirdPartySettings extends ConfigEntityBase implements ThirdPartySettingsInterface { use ThirdPartySettingsTrait; - protected $third_party_settings = array(); } diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ThirdPartySettingsTraitTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ThirdPartySettingsTraitTest.php index 3304c48..ce43331 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ThirdPartySettingsTraitTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ThirdPartySettingsTraitTest.php @@ -21,15 +21,13 @@ class ThirdPartySettingsTraitTest extends UnitTestCase { * @covers ::setThirdPartySetting * @covers ::unsetThirdPartySetting * @covers ::getThirdPartyProviders - * - * @dataProvider providerTestThirdPartySettings */ - public function testThirdPartySettings($third_party_settings_key = NULL) { + public function testThirdPartySettings() { $key = 'test'; $third_party = 'test_provider'; $value = $this->getRandomGenerator()->string(); - $trait_object = new TestThirdPartySettingsTrait($third_party_settings_key); + $trait_object = new TestThirdPartySettingsTrait(); // Test getThirdPartySetting() with no settings. $this->assertEquals($value, $trait_object->getThirdPartySetting($third_party, $key, $value)); @@ -48,20 +46,8 @@ public function testThirdPartySettings($third_party_settings_key = NULL) { $trait_object->unsetThirdPartySetting('test_provider2', $key); $this->assertEquals(array($third_party), $trait_object->getThirdPartyProviders()); } - - public function providerTestThirdPartySettings() { - return array(array(NULL), array('settings')); - } } class TestThirdPartySettingsTrait { use ThirdPartySettingsTrait; - - public function __construct($third_party_settings_key = NULL) { - if ($third_party_settings_key) { - $this->thirdPartySettingKey = $third_party_settings_key; - } - $this->{$this->thirdPartySettingKey} = array(); - } - }