diff --git a/core/lib/Drupal/Core/Config/Entity/ThirdPartySettingsInterface.php b/core/lib/Drupal/Core/Config/Entity/ThirdPartySettingsInterface.php index ae5f0bd..f016d65 100644 --- a/core/lib/Drupal/Core/Config/Entity/ThirdPartySettingsInterface.php +++ b/core/lib/Drupal/Core/Config/Entity/ThirdPartySettingsInterface.php @@ -28,6 +28,9 @@ * The setting value. * * @return $this + * + * @throws \Drupal\Core\Config\ConfigException + * If the third party providers property is not an array. */ public function setThirdPartySetting($module, $key, $value); @@ -43,6 +46,9 @@ public function setThirdPartySetting($module, $key, $value); * * @return mixed * The value. + * + * @throws \Drupal\Core\Config\ConfigException + * If the third party providers property is not an array. */ public function getThirdPartySetting($module, $key, $default); @@ -56,6 +62,9 @@ public function getThirdPartySetting($module, $key, $default); * * @return mixed * The value. + * + * @throws \Drupal\Core\Config\ConfigException + * If the third party providers property is not an array. */ public function unsetThirdPartySetting($module, $key); @@ -64,6 +73,9 @@ public function unsetThirdPartySetting($module, $key); * * @return array * The list of third parties. + * + * @throws \Drupal\Core\Config\ConfigException + * If the third party providers property is not an array. */ public function getThirdPartyProviders(); diff --git a/core/lib/Drupal/Core/Config/Entity/ThirdPartySettingsTrait.php b/core/lib/Drupal/Core/Config/Entity/ThirdPartySettingsTrait.php index b37367f..7161e78 100644 --- a/core/lib/Drupal/Core/Config/Entity/ThirdPartySettingsTrait.php +++ b/core/lib/Drupal/Core/Config/Entity/ThirdPartySettingsTrait.php @@ -7,17 +7,26 @@ namespace Drupal\Core\Config\Entity; +use Drupal\Core\Config\ConfigException; + /** * 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 default property used to store third party settings is + * 'third_party_settings'. This property should be an array. To override for a + * specific implement set $thirdPartySettingKey in the constructor. * * @see \Drupal\Core\Config\Entity\ThirdPartySettingsInterface */ trait ThirdPartySettingsTrait { + /** + * Name of the property on the class that stores third party settings. + * + * The property named should be an array. + * + * @var string + */ protected $thirdPartySettingKey = 'third_party_settings'; /** @@ -31,8 +40,12 @@ * The setting value. * * @return $this + * + * @throws \Drupal\Core\Config\ConfigException + * If the third party providers property is not an array. */ public function setThirdPartySetting($module, $key, $value) { + $this->checkThirdPartyArray(); $this->{$this->thirdPartySettingKey}[$module][$key] = $value; return $this; } @@ -49,8 +62,12 @@ public function setThirdPartySetting($module, $key, $value) { * * @return mixed * The value. + * + * @throws \Drupal\Core\Config\ConfigException + * If the third party providers property is not an array. */ public function getThirdPartySetting($module, $key, $default = NULL) { + $this->checkThirdPartyArray(); if (isset($this->{$this->thirdPartySettingKey}[$module][$key])) { return $this->{$this->thirdPartySettingKey}[$module][$key]; } @@ -69,8 +86,12 @@ public function getThirdPartySetting($module, $key, $default = NULL) { * * @return mixed * The value. + * + * @throws \Drupal\Core\Config\ConfigException + * If the third party providers property is not an array. */ public function unsetThirdPartySetting($module, $key) { + $this->checkThirdPartyArray(); unset($this->{$this->thirdPartySettingKey}[$module][$key]); // If the third party is no longer storing any information completely remove // the setting. @@ -85,9 +106,25 @@ public function unsetThirdPartySetting($module, $key) { * * @return array * The list of third parties. + * + * @throws \Drupal\Core\Config\ConfigException + * If the third party providers property is not an array. */ public function getThirdPartyProviders() { + $this->checkThirdPartyArray(); return array_keys($this->{$this->thirdPartySettingKey}); } + /** + * Checks that the third party settings property is an array. + * + * @throws \Drupal\Core\Config\ConfigException + * If the third party providers property is not an array. + */ + protected function checkThirdPartyArray() { + if (!is_array($this->{$this->thirdPartySettingKey})) { + throw new ConfigException('Third party settings storage should be an array.'); + } + } + }