Chris@0: getPluginDefinition(); Chris@0: if (!empty($definition['configuration'])) { Chris@0: return $definition['configuration']; Chris@0: } Chris@0: return []; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the definition of a configuration option. Chris@0: * Chris@17: * @param string $key Chris@17: * The key of the configuration option to get. Chris@17: * Chris@0: * @todo: This needs to go into an interface. Chris@0: * Chris@17: * @return \Drupal\Core\TypedData\DataDefinitionInterface|false Chris@0: * The typed data definition describing the configuration option, or FALSE Chris@0: * if the option does not exist. Chris@0: */ Chris@0: public function getConfigDefinition($key) { Chris@0: $definition = $this->getPluginDefinition(); Chris@0: if (!empty($definition['configuration'][$key])) { Chris@0: return $definition['configuration'][$key]; Chris@0: } Chris@0: return FALSE; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets all configuration values. Chris@0: * Chris@0: * @todo: This needs to go into an interface. Chris@0: * Chris@0: * @return array Chris@0: * The array of all configuration values, keyed by configuration option Chris@0: * name. Chris@0: */ Chris@0: public function getConfig() { Chris@0: return $this->configuration; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the value of a particular configuration option. Chris@0: * Chris@0: * @param string $key Chris@0: * The key of the configuration option to set. Chris@0: * @param mixed $value Chris@0: * The value to set. Chris@0: * Chris@0: * @todo This doesn't belong here. Move this into a new base class in Chris@0: * https://www.drupal.org/node/1764380. Chris@0: * @todo This does not set a value in \Drupal::config(), so the name is confusing. Chris@0: * Chris@0: * @return \Drupal\Core\Executable\ExecutablePluginBase Chris@0: * The executable object for chaining. Chris@17: * Chris@17: * @throws \Drupal\Component\Plugin\Exception\PluginException Chris@17: * If the provided configuration value does not pass validation. Chris@0: */ Chris@0: public function setConfig($key, $value) { Chris@0: if ($definition = $this->getConfigDefinition($key)) { Chris@0: $typed_data = \Drupal::typedDataManager()->create($definition, $value); Chris@0: Chris@0: if ($typed_data->validate()->count() > 0) { Chris@0: throw new PluginException("The provided configuration value does not pass validation."); Chris@0: } Chris@0: } Chris@0: $this->configuration[$key] = $value; Chris@0: return $this; Chris@0: } Chris@0: Chris@0: }