class PluginBase

Same name in this branch
  1. 10 core/modules/views/src/Plugin/views/PluginBase.php \Drupal\views\Plugin\views\PluginBase
  2. 10 core/lib/Drupal/Core/Plugin/PluginBase.php \Drupal\Core\Plugin\PluginBase
Same name in other branches
  1. 9 core/modules/views/src/Plugin/views/PluginBase.php \Drupal\views\Plugin\views\PluginBase
  2. 9 core/lib/Drupal/Core/Plugin/PluginBase.php \Drupal\Core\Plugin\PluginBase
  3. 9 core/lib/Drupal/Component/Plugin/PluginBase.php \Drupal\Component\Plugin\PluginBase
  4. 8.9.x core/modules/views/src/Plugin/views/PluginBase.php \Drupal\views\Plugin\views\PluginBase
  5. 8.9.x core/lib/Drupal/Core/Plugin/PluginBase.php \Drupal\Core\Plugin\PluginBase
  6. 8.9.x core/lib/Drupal/Component/Plugin/PluginBase.php \Drupal\Component\Plugin\PluginBase
  7. 11.x core/modules/views/src/Plugin/views/PluginBase.php \Drupal\views\Plugin\views\PluginBase
  8. 11.x core/lib/Drupal/Core/Plugin/PluginBase.php \Drupal\Core\Plugin\PluginBase
  9. 11.x core/lib/Drupal/Component/Plugin/PluginBase.php \Drupal\Component\Plugin\PluginBase

Base class for plugins wishing to support metadata inspection.

Hierarchy

Expanded class hierarchy of PluginBase

28 files declare their use of PluginBase
BlockContentDeletionTest.php in core/modules/block_content/tests/src/Kernel/BlockContentDeletionTest.php
BlockContentDeriverTest.php in core/modules/block_content/tests/src/Kernel/BlockContentDeriverTest.php
BlockContentTest.php in core/modules/block_content/tests/src/Kernel/BlockContentTest.php
ConfigActionManager.php in core/lib/Drupal/Core/Config/Action/ConfigActionManager.php
ConfigImporterMissingContentTest.php in core/tests/Drupal/KernelTests/Core/Config/ConfigImporterMissingContentTest.php

... See full list

File

core/lib/Drupal/Component/Plugin/PluginBase.php, line 8

Namespace

Drupal\Component\Plugin
View source
abstract class PluginBase implements PluginInspectionInterface, DerivativeInspectionInterface {
    
    /**
     * A string which is used to separate base plugin IDs from the derivative ID.
     */
    const DERIVATIVE_SEPARATOR = ':';
    
    /**
     * The plugin ID.
     *
     * @var string
     */
    protected $pluginId;
    
    /**
     * The plugin implementation definition.
     *
     * @var \Drupal\Component\Plugin\Definition\PluginDefinitionInterface|array
     */
    protected $pluginDefinition;
    
    /**
     * Configuration information passed into the plugin.
     *
     * When using an interface like
     * \Drupal\Component\Plugin\ConfigurableInterface, this is where the
     * configuration should be stored.
     *
     * Plugin configuration is optional, so plugin implementations must provide
     * their own setters and getters.
     *
     * @var array
     */
    protected $configuration;
    
    /**
     * Constructs a \Drupal\Component\Plugin\PluginBase object.
     *
     * @param array $configuration
     *   A configuration array containing information about the plugin instance.
     * @param string $plugin_id
     *   The plugin ID for the plugin instance.
     * @param mixed $plugin_definition
     *   The plugin implementation definition.
     */
    public function __construct(array $configuration, $plugin_id, $plugin_definition) {
        $this->configuration = $configuration;
        $this->pluginId = $plugin_id;
        $this->pluginDefinition = $plugin_definition;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getPluginId() {
        return $this->pluginId;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getBaseId() {
        $plugin_id = $this->getPluginId();
        if (strpos($plugin_id, static::DERIVATIVE_SEPARATOR)) {
            [
                $plugin_id,
            ] = explode(static::DERIVATIVE_SEPARATOR, $plugin_id, 2);
        }
        return $plugin_id;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getDerivativeId() {
        $plugin_id = $this->getPluginId();
        $derivative_id = NULL;
        if (strpos($plugin_id, static::DERIVATIVE_SEPARATOR)) {
            [
                ,
                $derivative_id,
            ] = explode(static::DERIVATIVE_SEPARATOR, $plugin_id, 2);
        }
        return $derivative_id;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getPluginDefinition() {
        return $this->pluginDefinition;
    }
    
    /**
     * Determines if the plugin is configurable.
     *
     * @return bool
     *   A boolean indicating whether the plugin is configurable.
     */
    public function isConfigurable() {
        return $this instanceof ConfigurableInterface;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
PluginBase::$configuration protected property Configuration information passed into the plugin.
PluginBase::$pluginDefinition protected property The plugin implementation definition.
PluginBase::$pluginId protected property The plugin ID.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition
PluginBase::getPluginId public function Gets the plugin ID of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 6

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.