Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / core / lib / Drupal / Core / Display / VariantBase.php
1 <?php
2
3 namespace Drupal\Core\Display;
4
5 use Drupal\Core\Cache\RefinableCacheableDependencyTrait;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\Core\Plugin\PluginBase;
8 use Drupal\Core\Plugin\PluginDependencyTrait;
9 use Drupal\Core\Session\AccountInterface;
10
11 /**
12  * Provides a base class for DisplayVariant plugins.
13  *
14  * @see \Drupal\Core\Display\Annotation\DisplayVariant
15  * @see \Drupal\Core\Display\VariantInterface
16  * @see \Drupal\Core\Display\VariantManager
17  * @see plugin_api
18  */
19 abstract class VariantBase extends PluginBase implements VariantInterface {
20
21   use PluginDependencyTrait;
22   use RefinableCacheableDependencyTrait;
23
24   /**
25    * {@inheritdoc}
26    */
27   public function __construct(array $configuration, $plugin_id, $plugin_definition) {
28     parent::__construct($configuration, $plugin_id, $plugin_definition);
29
30     $this->setConfiguration($configuration);
31   }
32
33   /**
34    * {@inheritdoc}
35    */
36   public function label() {
37     return $this->configuration['label'];
38   }
39
40   /**
41    * {@inheritdoc}
42    */
43   public function adminLabel() {
44     return $this->pluginDefinition['admin_label'];
45   }
46
47   /**
48    * {@inheritdoc}
49    */
50   public function id() {
51     return $this->configuration['uuid'];
52   }
53
54   /**
55    * {@inheritdoc}
56    */
57   public function getWeight() {
58     return (int) $this->configuration['weight'];
59   }
60
61   /**
62    * {@inheritdoc}
63    */
64   public function setWeight($weight) {
65     $this->configuration['weight'] = (int) $weight;
66   }
67
68   /**
69    * {@inheritdoc}
70    */
71   public function getConfiguration() {
72     return [
73       'id' => $this->getPluginId(),
74     ] + $this->configuration;
75   }
76
77   /**
78    * {@inheritdoc}
79    */
80   public function setConfiguration(array $configuration) {
81     $this->configuration = $configuration + $this->defaultConfiguration();
82     return $this;
83   }
84
85   /**
86    * {@inheritdoc}
87    */
88   public function defaultConfiguration() {
89     return [
90       'label' => '',
91       'uuid' => '',
92       'weight' => 0,
93     ];
94   }
95
96   /**
97    * {@inheritdoc}
98    */
99   public function calculateDependencies() {
100     return $this->dependencies;
101   }
102
103   /**
104    * {@inheritdoc}
105    */
106   public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
107     $form['label'] = [
108       '#type' => 'textfield',
109       '#title' => $this->t('Label'),
110       '#description' => $this->t('The label for this display variant.'),
111       '#default_value' => $this->label(),
112       '#maxlength' => '255',
113     ];
114     return $form;
115   }
116
117   /**
118    * {@inheritdoc}
119    */
120   public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
121   }
122
123   /**
124    * {@inheritdoc}
125    */
126   public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
127     $this->configuration['label'] = $form_state->getValue('label');
128   }
129
130   /**
131    * {@inheritdoc}
132    */
133   public function access(AccountInterface $account = NULL) {
134     return TRUE;
135   }
136
137 }