function TextFieldItemList::defaultValuesFormValidate

Same name and namespace in other branches
  1. 10 core/modules/text/src/Plugin/Field/FieldType/TextFieldItemList.php \Drupal\text\Plugin\Field\FieldType\TextFieldItemList::defaultValuesFormValidate()

Overrides FieldItemList::defaultValuesFormValidate

File

core/modules/text/src/Plugin/Field/FieldType/TextFieldItemList.php, line 16

Class

TextFieldItemList
Defines an item list class for text fields.

Namespace

Drupal\text\Plugin\Field\FieldType

Code

public function defaultValuesFormValidate(array $element, array &$form, FormStateInterface $form_state) {
    if ($allowed_formats = $this->getSetting('allowed_formats')) {
        $field_name = $this->definition
            ->getName();
        $submitted_values = $form_state->getValue([
            'default_value_input',
            $field_name,
        ]);
        foreach ($submitted_values as $delta => $value) {
            if (!in_array($value['format'], $allowed_formats, TRUE)) {
                $form_state->setErrorByName("default_value_input][{$field_name}][{$delta}][format", $this->t("The selected text format is not allowed."));
            }
        }
    }
    parent::defaultValuesFormValidate($element, $form, $form_state);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.