69a660e4db47f0b9f3d48fd55c166eec1b9a58be
[yaffs-website] / web / core / modules / text / src / Plugin / Field / FieldWidget / TextareaWidget.php
1 <?php
2
3 namespace Drupal\text\Plugin\Field\FieldWidget;
4
5 use Drupal\Core\Field\FieldItemListInterface;
6 use Drupal\Core\Field\Plugin\Field\FieldWidget\StringTextareaWidget;
7 use Drupal\Core\Form\FormStateInterface;
8 use Symfony\Component\Validator\ConstraintViolationInterface;
9
10 /**
11  * Plugin implementation of the 'text_textarea' widget.
12  *
13  * @FieldWidget(
14  *   id = "text_textarea",
15  *   label = @Translation("Text area (multiple rows)"),
16  *   field_types = {
17  *     "text_long"
18  *   }
19  * )
20  */
21 class TextareaWidget extends StringTextareaWidget {
22
23   /**
24    * {@inheritdoc}
25    */
26   public function settingsForm(array $form, FormStateInterface $form_state) {
27     $element = parent::settingsForm($form, $form_state);
28     $element['rows']['#description'] = $this->t('Text editors (like CKEditor) may override this setting.');
29     return $element;
30   }
31
32   /**
33    * {@inheritdoc}
34    */
35   public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
36     $main_widget = parent::formElement($items, $delta, $element, $form, $form_state);
37
38     $element = $main_widget['value'];
39     $element['#type'] = 'text_format';
40     $element['#format'] = $items[$delta]->format;
41     $element['#base_type'] = $main_widget['value']['#type'];
42     return $element;
43   }
44
45   /**
46    * {@inheritdoc}
47    */
48   public function errorElement(array $element, ConstraintViolationInterface $violation, array $form, FormStateInterface $form_state) {
49     if ($violation->arrayPropertyPath == ['format'] && isset($element['format']['#access']) && !$element['format']['#access']) {
50       // Ignore validation errors for formats if formats may not be changed,
51       // i.e. when existing formats become invalid. See filter_process_format().
52       return FALSE;
53     }
54     return $element;
55   }
56
57 }