3 namespace Drupal\Core\Executable;
5 use Drupal\Core\Plugin\ContextAwarePluginBase;
6 use Drupal\Component\Plugin\Exception\PluginException;
9 * Provides the basic architecture for executable plugins.
11 abstract class ExecutablePluginBase extends ContextAwarePluginBase implements ExecutableInterface {
14 * Gets an array of definitions of available configuration options.
16 * @todo: This needs to go into an interface.
19 * An array of typed data definitions describing available configuration
20 * options, keyed by option name.
22 public function getConfigDefinitions() {
23 $definition = $this->getPluginDefinition();
24 if (!empty($definition['configuration'])) {
25 return $definition['configuration'];
31 * Gets the definition of a configuration option.
33 * @todo: This needs to go into an interface.
36 * The typed data definition describing the configuration option, or FALSE
37 * if the option does not exist.
39 public function getConfigDefinition($key) {
40 $definition = $this->getPluginDefinition();
41 if (!empty($definition['configuration'][$key])) {
42 return $definition['configuration'][$key];
48 * Gets all configuration values.
50 * @todo: This needs to go into an interface.
53 * The array of all configuration values, keyed by configuration option
56 public function getConfig() {
57 return $this->configuration;
61 * Sets the value of a particular configuration option.
64 * The key of the configuration option to set.
68 * @todo This doesn't belong here. Move this into a new base class in
69 * https://www.drupal.org/node/1764380.
70 * @todo This does not set a value in \Drupal::config(), so the name is confusing.
72 * @return \Drupal\Core\Executable\ExecutablePluginBase
73 * The executable object for chaining.
75 public function setConfig($key, $value) {
76 if ($definition = $this->getConfigDefinition($key)) {
77 $typed_data = \Drupal::typedDataManager()->create($definition, $value);
79 if ($typed_data->validate()->count() > 0) {
80 throw new PluginException("The provided configuration value does not pass validation.");
83 $this->configuration[$key] = $value;