3 namespace Drupal\filter\Plugin;
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\Core\Plugin\PluginBase;
9 * Provides a base class for Filter plugins.
11 * @see \Drupal\filter\Annotation\Filter
12 * @see \Drupal\filter\FilterPluginManager
13 * @see \Drupal\filter\Plugin\FilterInterface
16 abstract class FilterBase extends PluginBase implements FilterInterface {
19 * The name of the provider that owns this filter.
26 * A Boolean indicating whether this filter is enabled.
30 public $status = FALSE;
33 * The weight of this filter compared to others in a filter collection.
40 * An associative array containing the configured settings of this filter.
44 public $settings = [];
49 public function __construct(array $configuration, $plugin_id, $plugin_definition) {
50 parent::__construct($configuration, $plugin_id, $plugin_definition);
52 $this->provider = $this->pluginDefinition['provider'];
54 $this->setConfiguration($configuration);
60 public function setConfiguration(array $configuration) {
61 if (isset($configuration['status'])) {
62 $this->status = (bool) $configuration['status'];
64 if (isset($configuration['weight'])) {
65 $this->weight = (int) $configuration['weight'];
67 if (isset($configuration['settings'])) {
68 $this->settings = (array) $configuration['settings'];
76 public function getConfiguration() {
78 'id' => $this->getPluginId(),
79 'provider' => $this->pluginDefinition['provider'],
80 'status' => $this->status,
81 'weight' => $this->weight,
82 'settings' => $this->settings,
89 public function defaultConfiguration() {
91 'provider' => $this->pluginDefinition['provider'],
93 'weight' => $this->pluginDefinition['weight'] ?: 0,
94 'settings' => $this->pluginDefinition['settings'],
101 public function calculateDependencies() {
108 public function getType() {
109 return $this->pluginDefinition['type'];
115 public function getLabel() {
116 return $this->pluginDefinition['title'];
122 public function getDescription() {
123 return $this->pluginDefinition['description'];
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.
139 public function prepare($text, $langcode) {
146 public function getHTMLRestrictions() {
153 public function tips($long = FALSE) {