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 @@ -62,11 +62,7 @@ 'value' => [ 'Length' => [ 'max' => $max_length, - 'maxMessage' => t('%name: the text may not be longer than @max characters.', [ - '%name' => $this->getFieldDefinition() - ->getLabel(), - '@max' => $max_length, - ]), + 'maxMessage' => t('%name: the text may not be longer than @max characters.', ['%name' => $this->getFieldDefinition()->getLabel(), '@max' => $max_length]), ], ], ]); diff -u b/core/modules/text/src/Plugin/Field/FieldType/TextItemBase.php b/core/modules/text/src/Plugin/Field/FieldType/TextItemBase.php --- b/core/modules/text/src/Plugin/Field/FieldType/TextItemBase.php +++ b/core/modules/text/src/Plugin/Field/FieldType/TextItemBase.php @@ -49,7 +49,7 @@ * @see static::fieldSettingsForm() */ public static function validateAllowedFormats(array &$element, FormStateInterface $form_state) { - $value = array_values(array_filter($element['#value'])); + $value = array_values(array_filter($form_state->getValue($element['#parents']))); $form_state->setValueForElement($element, $value); } diff -u b/core/modules/text/tests/src/Functional/TextFieldTest.php b/core/modules/text/tests/src/Functional/TextFieldTest.php --- b/core/modules/text/tests/src/Functional/TextFieldTest.php +++ b/core/modules/text/tests/src/Functional/TextFieldTest.php @@ -170,31 +170,18 @@ public function testTextfieldWidgetsAllowedFormats() { // Create one text format. $this->drupalLogin($this->adminUser); - $edit = [ + $format1 = FilterFormat::create([ 'format' => mb_strtolower($this->randomMachineName()), 'name' => $this->randomMachineName(), - ]; - $this->drupalGet('admin/config/content/formats/add'); - $this->submitForm($edit, 'Save configuration'); - filter_formats_reset(); - /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */ - $entity_type_manager = $this->container->get('entity_type.manager'); - $filter_format_storage = $entity_type_manager - ->getStorage('filter_format'); - /** @var \Drupal\filter\Entity\FilterFormat $format1 */ - $format1 = $filter_format_storage->load($edit['format']); + ]); $format1_id = $format1->id(); // Create a second text format. - $edit = [ + $format2 = FilterFormat::create([ 'format' => mb_strtolower($this->randomMachineName()), 'name' => $this->randomMachineName(), - ]; - $this->drupalGet('admin/config/content/formats/add'); - $this->submitForm($edit, 'Save configuration'); - filter_formats_reset(); - /** @var \Drupal\filter\Entity\FilterFormat $format2 */ - $format2 = $filter_format_storage->load($edit['format']); + ]); + $format1_id = $format1->id(); // Grant access to both formats to the user. $roles = $this->webUser->getRoles(); diff -u b/core/modules/text/tests/src/Kernel/TextWithSummaryItemTest.php b/core/modules/text/tests/src/Kernel/TextWithSummaryItemTest.php --- b/core/modules/text/tests/src/Kernel/TextWithSummaryItemTest.php +++ b/core/modules/text/tests/src/Kernel/TextWithSummaryItemTest.php @@ -68,6 +68,15 @@ $entity->name->value = $this->randomMachineName(); $entity->save(); + // Test constraint failure. + $entity_fail = $storage->create(); + $entity_fail->summary_field->value = $this->randomMachineName(); + $entity_fail->summary_field->summary = $this->randomMachineName(); + $entity_fail->summary_field->format = 'failure_format'; + $entity_fail->name->value = $this->randomMachineName(); + $violations = $entity_fail->validate(); + $this->assertCount(2, $violations); + $entity = $storage->load($entity->id()); $this->assertInstanceOf(FieldItemListInterface::class, $entity->summary_field); $this->assertInstanceOf(FieldItemInterface::class, $entity->summary_field[0]);