diff -u b/core/modules/text/src/Plugin/Field/FieldType/TextItem.php b/core/modules/text/src/Plugin/Field/FieldType/TextItem.php --- b/core/modules/text/src/Plugin/Field/FieldType/TextItem.php +++ b/core/modules/text/src/Plugin/Field/FieldType/TextItem.php @@ -57,14 +57,30 @@ $constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager(); $constraints = parent::getConstraints(); + $constraint_values = []; if ($max_length = $this->getSetting('max_length')) { - $constraints[] = $constraint_manager->create('ComplexData', [ - 'value' => [ - 'Length' => [ - 'max' => $max_length, - 'maxMessage' => t('%name: the text may not be longer than @max characters.', ['%name' => $this->getFieldDefinition()->getLabel(), '@max' => $max_length]), + $constraint_values[] = [ + 'Length' => [ + 'max' => $max_length, + 'maxMessage' => t('%name: the text may not be longer than @max characters.', ['%name' => $this->getFieldDefinition()->getLabel(), '@max' => $max_length,]), + ], + ]; + } + + if ($formats = $this::getParent()->getSetting('allowed_formats')) { + $constraint_values[] = [ + 'format' => [ + 'AllowedValues' => [ + 'choices' => $formats, + 'choicesMessage' => t('%name: the selected format is not one the allowed formats.', ['%name' => $this->getFieldDefinition()->getLabel(),]) ], ], + ]; + } + + if (!empty($constraint_values)) { + $constraints[] = $constraint_manager->create('ComplexData', [ + 'value' => $constraint_values, ]); }