abstract class PluginBase

You are here

  1. 8 core/lib/Drupal/Core/Plugin/PluginBase.php PluginBase
  2. 8 core/modules/views/lib/Drupal/views/Plugin/views/PluginBase.php PluginBase
  3. 8 core/lib/Drupal/Component/Plugin/PluginBase.php PluginBase

Base class for plugins wishing to support metadata inspection.

Namespace

Drupal\Component\Plugin

Hierarchy

Expanded class hierarchy of PluginBase

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
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::getBasePluginId public function Returns the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBasePluginId
PluginBase::getDerivativeId public function Returns the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Returns the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition
PluginBase::getPluginId public function Returns the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::__construct public function Constructs a Drupal\Component\Plugin\PluginBase object.

File

core/lib/Drupal/Component/Plugin/PluginBase.php, line 12
Contains \Drupal\Component\Plugin\PluginBase

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 array
   */
  protected $pluginDefinition;

  /**
   * Configuration information passed into the plugin.
   *
   * @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 getBasePluginId() {
    $plugin_id = $this->getPluginId();
    if (strpos($plugin_id, static::DERIVATIVE_SEPARATOR)) {
      list($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)) {
      list(, $derivative_id) = explode(static::DERIVATIVE_SEPARATOR, $plugin_id, 2);
    }
    return $derivative_id;
  }

  /**
   * {@inheritdoc}
   */
  public function getPluginDefinition() {
    return $this->pluginDefinition;
  }

  // Note: Plugin configuration is optional so its left to the plugin type to
  // require a getter as part of its interface.
}
13 files declare their use of PluginBase
ConfigEntityBaseUnitTest.php in core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php
Contains \Drupal\Tests\Core\Config\Entity\ConfigEntityBaseUnitTest.
DrupalImageCaption.php in core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/CKEditorPlugin/DrupalImageCaption.php
Contains \Drupal\ckeditor\Plugin\CKEditorPlugin\DrupalImageWidget.
Editor.php in core/modules/editor/lib/Drupal/editor/Plugin/InPlaceEditor/Editor.php
Contains \Drupal\editor\Plugin\InPlaceEditor\Editor.
Llama.php in core/modules/ckeditor/tests/modules/lib/Drupal/ckeditor_test/Plugin/CKEditorPlugin/Llama.php
Contains \Drupal\ckeditor_test\Plugin\CKEditorPlugin\Llama.
LlamaButton.php in core/modules/ckeditor/tests/modules/lib/Drupal/ckeditor_test/Plugin/CKEditorPlugin/LlamaButton.php
Contains \Drupal\ckeditor_test\Plugin\CKEditorPlugin\LlamaButton.

... See full list