6cd8f3e4b6ea6e33841ba12fc9e676f342895b42
[yaffs-website] / web / modules / contrib / linkit / src / Plugin / Linkit / Attribute / Title.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\linkit\Plugin\Linkit\Attribute\Title.
6  */
7
8 namespace Drupal\linkit\Plugin\Linkit\Attribute;
9
10 use Drupal\Core\Form\FormStateInterface;
11 use Drupal\linkit\ConfigurableAttributeBase;
12
13 /**
14  * Title attribute.
15  *
16  * @Attribute(
17  *   id = "title",
18  *   label = @Translation("Title"),
19  *   html_name = "title",
20  *   description = @Translation("Basic input field for the title attribute.")
21  * )
22  */
23 class Title extends ConfigurableAttributeBase {
24
25   /**
26    * {@inheritdoc}
27    */
28   public function buildFormElement($default_value) {
29     $element = [
30       '#type' => 'textfield',
31       '#title' => t('Title'),
32       '#default_value' => $default_value,
33       '#maxlength' => 255,
34       '#size' => 40,
35       '#placeholder' => t('The "title" attribute value'),
36     ];
37
38     if ($this->configuration['automatic_title']) {
39       $element['#attached']['library'][] = 'linkit/linkit.attribute.title';
40       $element['#placeholder'] = t('The "title" attribute value (auto populated)');
41     }
42
43     return $element;
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function defaultConfiguration() {
50     return parent::defaultConfiguration() + [
51       'automatic_title' => FALSE,
52     ];
53   }
54
55   /**
56    * {@inheritdoc}
57    */
58   public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
59     $form['automatic_title'] = [
60       '#type' => 'checkbox',
61       '#title' => $this->t('Automatically populate title'),
62       '#default_value' => $this->configuration['automatic_title'],
63       '#description' => $this->t('Automatically populate the title attribute with the title from the match selection.'),
64     ];
65
66     return $form;
67   }
68
69   /**
70    * {@inheritdoc}
71    */
72   public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
73   }
74
75   /**
76    * {@inheritdoc}
77    */
78   public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
79     $this->configuration['automatic_title'] = $form_state->getValue('automatic_title');
80   }
81
82 }