Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ExecutablePluginBase.php

class ExecutablePluginBase

Provides the basic architecture for executable plugins.

Hierarchy

  • class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
    • class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
      • class \Drupal\Core\Executable\ExecutablePluginBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Executable\ExecutableInterface, \Drupal\Core\Cache\CacheableDependencyInterface, \Drupal\Core\Plugin\ContextAwarePluginInterface uses \Drupal\Core\Plugin\ContextAwarePluginTrait

Expanded class hierarchy of ExecutablePluginBase

1 file declares its use of ExecutablePluginBase
ConditionPluginBase.php in core/lib/Drupal/Core/Condition/ConditionPluginBase.php

File

core/lib/Drupal/Core/Executable/ExecutablePluginBase.php, line 14

Namespace

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

}

Members

Title Sort descending Modifiers Object type Summary Overrides
ContextAwarePluginTrait::$context protected property The data objects representing the context of this plugin.
ContextAwarePluginTrait::getCacheContexts public function 7
ContextAwarePluginTrait::getCacheMaxAge public function 2
ContextAwarePluginTrait::getCacheTags public function 2
ContextAwarePluginTrait::getContext public function
ContextAwarePluginTrait::getContextDefinition public function
ContextAwarePluginTrait::getContextDefinitions public function
ContextAwarePluginTrait::getContextMapping public function 1
ContextAwarePluginTrait::getContexts public function
ContextAwarePluginTrait::getContextValue public function
ContextAwarePluginTrait::getContextValues public function
ContextAwarePluginTrait::getPluginDefinition abstract public function 1
ContextAwarePluginTrait::setContext public function 1
ContextAwarePluginTrait::setContextMapping public function
ContextAwarePluginTrait::setContextValue public function
ContextAwarePluginTrait::validateContexts public function
ExecutableInterface::execute public function Executes the plugin. 14
ExecutablePluginBase::getConfig public function Gets all configuration values.
ExecutablePluginBase::getConfigDefinition public function Gets the definition of a configuration option.
ExecutablePluginBase::getConfigDefinitions public function Gets an array of definitions of available configuration options.
ExecutablePluginBase::setConfig public function Sets the value of a particular configuration option.
PluginInspectionInterface::getPluginId public function Gets the plugin ID of the plugin instance. 2

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal