annotate core/lib/Drupal/Component/Plugin/PluginBase.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Component\Plugin;
Chris@0 4
Chris@0 5 /**
Chris@0 6 * Base class for plugins wishing to support metadata inspection.
Chris@0 7 */
Chris@0 8 abstract class PluginBase implements PluginInspectionInterface, DerivativeInspectionInterface {
Chris@0 9
Chris@0 10 /**
Chris@0 11 * A string which is used to separate base plugin IDs from the derivative ID.
Chris@0 12 */
Chris@0 13 const DERIVATIVE_SEPARATOR = ':';
Chris@0 14
Chris@0 15 /**
Chris@0 16 * The plugin_id.
Chris@0 17 *
Chris@0 18 * @var string
Chris@0 19 */
Chris@0 20 protected $pluginId;
Chris@0 21
Chris@0 22 /**
Chris@0 23 * The plugin implementation definition.
Chris@0 24 *
Chris@0 25 * @var array
Chris@0 26 */
Chris@0 27 protected $pluginDefinition;
Chris@0 28
Chris@0 29 /**
Chris@0 30 * Configuration information passed into the plugin.
Chris@0 31 *
Chris@0 32 * When using an interface like
Chris@18 33 * \Drupal\Component\Plugin\ConfigurableInterface, this is where the
Chris@0 34 * configuration should be stored.
Chris@0 35 *
Chris@0 36 * Plugin configuration is optional, so plugin implementations must provide
Chris@0 37 * their own setters and getters.
Chris@0 38 *
Chris@0 39 * @var array
Chris@0 40 */
Chris@0 41 protected $configuration;
Chris@0 42
Chris@0 43 /**
Chris@17 44 * Constructs a \Drupal\Component\Plugin\PluginBase object.
Chris@0 45 *
Chris@0 46 * @param array $configuration
Chris@0 47 * A configuration array containing information about the plugin instance.
Chris@0 48 * @param string $plugin_id
Chris@0 49 * The plugin_id for the plugin instance.
Chris@0 50 * @param mixed $plugin_definition
Chris@0 51 * The plugin implementation definition.
Chris@0 52 */
Chris@0 53 public function __construct(array $configuration, $plugin_id, $plugin_definition) {
Chris@0 54 $this->configuration = $configuration;
Chris@0 55 $this->pluginId = $plugin_id;
Chris@0 56 $this->pluginDefinition = $plugin_definition;
Chris@18 57
Chris@18 58 if ($this instanceof ConfigurablePluginInterface && !$this instanceof ConfigurableInterface) {
Chris@18 59 @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);
Chris@18 60 }
Chris@0 61 }
Chris@0 62
Chris@0 63 /**
Chris@0 64 * {@inheritdoc}
Chris@0 65 */
Chris@0 66 public function getPluginId() {
Chris@0 67 return $this->pluginId;
Chris@0 68 }
Chris@0 69
Chris@0 70 /**
Chris@0 71 * {@inheritdoc}
Chris@0 72 */
Chris@0 73 public function getBaseId() {
Chris@0 74 $plugin_id = $this->getPluginId();
Chris@0 75 if (strpos($plugin_id, static::DERIVATIVE_SEPARATOR)) {
Chris@0 76 list($plugin_id) = explode(static::DERIVATIVE_SEPARATOR, $plugin_id, 2);
Chris@0 77 }
Chris@0 78 return $plugin_id;
Chris@0 79 }
Chris@0 80
Chris@0 81 /**
Chris@0 82 * {@inheritdoc}
Chris@0 83 */
Chris@0 84 public function getDerivativeId() {
Chris@0 85 $plugin_id = $this->getPluginId();
Chris@0 86 $derivative_id = NULL;
Chris@0 87 if (strpos($plugin_id, static::DERIVATIVE_SEPARATOR)) {
Chris@0 88 list(, $derivative_id) = explode(static::DERIVATIVE_SEPARATOR, $plugin_id, 2);
Chris@0 89 }
Chris@0 90 return $derivative_id;
Chris@0 91 }
Chris@0 92
Chris@0 93 /**
Chris@0 94 * {@inheritdoc}
Chris@0 95 */
Chris@0 96 public function getPluginDefinition() {
Chris@0 97 return $this->pluginDefinition;
Chris@0 98 }
Chris@0 99
Chris@18 100 /**
Chris@18 101 * Determines if the plugin is configurable.
Chris@18 102 *
Chris@18 103 * @return bool
Chris@18 104 * A boolean indicating whether the plugin is configurable.
Chris@18 105 */
Chris@18 106 public function isConfigurable() {
Chris@18 107 return $this instanceof ConfigurableInterface || $this instanceof ConfigurablePluginInterface;
Chris@18 108 }
Chris@18 109
Chris@0 110 }