Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / filter / src / Plugin / FilterBase.php
1 <?php
2
3 namespace Drupal\filter\Plugin;
4
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\Core\Plugin\PluginBase;
7
8 /**
9  * Provides a base class for Filter plugins.
10  *
11  * @see \Drupal\filter\Annotation\Filter
12  * @see \Drupal\filter\FilterPluginManager
13  * @see \Drupal\filter\Plugin\FilterInterface
14  * @see plugin_api
15  */
16 abstract class FilterBase extends PluginBase implements FilterInterface {
17
18   /**
19    * The name of the provider that owns this filter.
20    *
21    * @var string
22    */
23   public $provider;
24
25   /**
26    * A Boolean indicating whether this filter is enabled.
27    *
28    * @var bool
29    */
30   public $status = FALSE;
31
32   /**
33    * The weight of this filter compared to others in a filter collection.
34    *
35    * @var int
36    */
37   public $weight = 0;
38
39   /**
40    * An associative array containing the configured settings of this filter.
41    *
42    * @var array
43    */
44   public $settings = [];
45
46   /**
47    * {@inheritdoc}
48    */
49   public function __construct(array $configuration, $plugin_id, $plugin_definition) {
50     parent::__construct($configuration, $plugin_id, $plugin_definition);
51
52     $this->provider = $this->pluginDefinition['provider'];
53
54     $this->setConfiguration($configuration);
55   }
56
57   /**
58    * {@inheritdoc}
59    */
60   public function setConfiguration(array $configuration) {
61     if (isset($configuration['status'])) {
62       $this->status = (bool) $configuration['status'];
63     }
64     if (isset($configuration['weight'])) {
65       $this->weight = (int) $configuration['weight'];
66     }
67     if (isset($configuration['settings'])) {
68       $this->settings = (array) $configuration['settings'];
69     }
70     return $this;
71   }
72
73   /**
74    * {@inheritdoc}
75    */
76   public function getConfiguration() {
77     return [
78       'id' => $this->getPluginId(),
79       'provider' => $this->pluginDefinition['provider'],
80       'status' => $this->status,
81       'weight' => $this->weight,
82       'settings' => $this->settings,
83     ];
84   }
85
86   /**
87    * {@inheritdoc}
88    */
89   public function defaultConfiguration() {
90     return [
91       'provider' => $this->pluginDefinition['provider'],
92       'status' => FALSE,
93       'weight' => $this->pluginDefinition['weight'] ?: 0,
94       'settings' => $this->pluginDefinition['settings'],
95     ];
96   }
97
98   /**
99    * {@inheritdoc}
100    */
101   public function calculateDependencies() {
102     return [];
103   }
104
105   /**
106    * {@inheritdoc}
107    */
108   public function getType() {
109     return $this->pluginDefinition['type'];
110   }
111
112   /**
113    * {@inheritdoc}
114    */
115   public function getLabel() {
116     return $this->pluginDefinition['title'];
117   }
118
119   /**
120    * {@inheritdoc}
121    */
122   public function getDescription() {
123     return $this->pluginDefinition['description'];
124   }
125
126   /**
127    * {@inheritdoc}
128    */
129   public function settingsForm(array $form, FormStateInterface $form_state) {
130     // Implementations should work with and return $form. Returning an empty
131     // array here allows the text format administration form to identify whether
132     // the filter plugin has any settings form elements.
133     return [];
134   }
135
136   /**
137    * {@inheritdoc}
138    */
139   public function prepare($text, $langcode) {
140     return $text;
141   }
142
143   /**
144    * {@inheritdoc}
145    */
146   public function getHTMLRestrictions() {
147     return FALSE;
148   }
149
150   /**
151    * {@inheritdoc}
152    */
153   public function tips($long = FALSE) {
154   }
155
156 }