Further modules included.
[yaffs-website] / web / modules / contrib / linkit / src / AttributeBase.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\linkit\AttributeBase.
6  */
7
8 namespace Drupal\linkit;
9
10 use Drupal\Core\Plugin\PluginBase;
11
12 /**
13  * Provides a base class for attribute plugins.
14  *
15  * @see \Drupal\linkit\Annotation\Attribute
16  * @see \Drupal\linkit\AttributeBase
17  * @see \Drupal\linkit\AttributeManager
18  * @see plugin_api
19  */
20 abstract class AttributeBase extends PluginBase implements AttributeInterface {
21
22   /**
23    * The weight of the attribute compared to others in an attribute collection.
24    *
25    * @var int
26    */
27   protected $weight = 0;
28
29   /**
30    * {@inheritdoc}
31    */
32   public function __construct(array $configuration, $plugin_id, $plugin_definition) {
33     parent::__construct($configuration, $plugin_id, $plugin_definition);
34
35     $this->setConfiguration($configuration);
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   public function getConfiguration() {
42     return [
43       'id' => $this->getPluginId(),
44       'weight' => $this->weight,
45       'settings' => $this->configuration,
46     ];
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   public function setConfiguration(array $configuration) {
53     $configuration += [
54       'weight' => '0',
55       'settings' => [],
56     ];
57     $this->configuration = $configuration['settings'] + $this->defaultConfiguration();
58     $this->weight = $configuration['weight'];
59     return $this;
60   }
61
62   /**
63    * {@inheritdoc}
64    */
65   public function defaultConfiguration() {
66     return [];
67   }
68
69   /**
70    * {@inheritdoc}
71    */
72   public function calculateDependencies() {
73     return [];
74   }
75
76   /**
77    * {@inheritdoc}
78    */
79   public function getLabel() {
80     return $this->pluginDefinition['label'];
81   }
82
83   /**
84    * {@inheritdoc}
85    */
86   public function getHtmlName() {
87     return $this->pluginDefinition['html_name'];
88   }
89
90   /**
91    * {@inheritdoc}
92    */
93   public function getDescription() {
94     return $this->pluginDefinition['description'];
95   }
96
97   /**
98    * {@inheritdoc}
99    */
100   public function getWeight() {
101     return $this->weight;
102   }
103
104   /**
105    * {@inheritdoc}
106    */
107   public function setWeight($weight) {
108     $this->weight = $weight;
109     return $this;
110   }
111
112 }