123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace Drupal\Component\Plugin;
- /**
- * Base class for plugins wishing to support metadata inspection.
- */
- 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.
- *
- * 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;
- if ($this instanceof ConfigurablePluginInterface && !$this instanceof ConfigurableInterface) {
- @trigger_error('Drupal\Component\Plugin\ConfigurablePluginInterface is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. You should implement ConfigurableInterface and/or DependentPluginInterface directly as needed. If you implement ConfigurableInterface you may choose to implement ConfigurablePluginInterface in Drupal 8 as well for maximum compatibility, however this must be removed prior to Drupal 9. See https://www.drupal.org/node/2946161', E_USER_DEPRECATED);
- }
- }
- /**
- * {@inheritdoc}
- */
- public function getPluginId() {
- return $this->pluginId;
- }
- /**
- * {@inheritdoc}
- */
- public function getBaseId() {
- $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;
- }
- /**
- * Determines if the plugin is configurable.
- *
- * @return bool
- * A boolean indicating whether the plugin is configurable.
- */
- public function isConfigurable() {
- return $this instanceof ConfigurableInterface || $this instanceof ConfigurablePluginInterface;
- }
- }
|