3 namespace Drupal\Core\Field\Plugin\Field\FieldWidget;
5 use Drupal\Core\Field\FieldItemListInterface;
6 use Drupal\Core\Field\WidgetBase;
7 use Drupal\Core\Form\FormStateInterface;
10 * Plugin implementation of the 'string_textarea' widget.
13 * id = "string_textarea",
14 * label = @Translation("Text area (multiple rows)"),
20 class StringTextareaWidget extends WidgetBase {
25 public static function defaultSettings() {
29 ] + parent::defaultSettings();
35 public function settingsForm(array $form, FormStateInterface $form_state) {
38 '#title' => t('Rows'),
39 '#default_value' => $this->getSetting('rows'),
43 $element['placeholder'] = [
44 '#type' => 'textfield',
45 '#title' => t('Placeholder'),
46 '#default_value' => $this->getSetting('placeholder'),
47 '#description' => t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'),
55 public function settingsSummary() {
58 $summary[] = t('Number of rows: @rows', ['@rows' => $this->getSetting('rows')]);
59 $placeholder = $this->getSetting('placeholder');
60 if (!empty($placeholder)) {
61 $summary[] = t('Placeholder: @placeholder', ['@placeholder' => $placeholder]);
70 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
71 $element['value'] = $element + [
72 '#type' => 'textarea',
73 '#default_value' => $items[$delta]->value,
74 '#rows' => $this->getSetting('rows'),
75 '#placeholder' => $this->getSetting('placeholder'),
76 '#attributes' => ['class' => ['js-text-full', 'text-full']],