diff -u b/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php b/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php --- b/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php +++ b/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php @@ -117,8 +117,8 @@ ); $form['cardinality_container']['cardinality_number'] = array( '#type' => 'number', - '#description' => ($highest_delta > 1) ? $this->t("Minimum is !min, as there is data for this field.", ['!min' => $highest_delta]) : '', - '#default_value' => $cardinality != FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED ? $cardinality : 1, + '#description' => ($highest_delta > 1) ? $this->t("Minimum is @min, as there is data for this field.", ['@min' => $highest_delta]) : '', + '#default_value' => $cardinality != FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED ? $cardinality : $highest_delta, '#min' => $highest_delta, '#title' => $this->t('Limit'), '#title_display' => 'invisible', @@ -162,7 +162,7 @@ // Increment by one, since delta starts from 0. $highest_delta = $this->entity->getHighestDelta() + 1; if ($highest_delta > $form_state->getValue('cardinality_number')) { - $form_state->setErrorByName('cardinality_number', $this->t('You can not set the cardinality lower than @delta', array('@delta' => $highest_delta))); + $form_state->setErrorByName('cardinality_number', $this->t('You can not set the cardinality lower than @delta', ['@delta' => $highest_delta])); } } } diff -u b/core/modules/field_ui/src/Tests/ManageFieldsTest.php b/core/modules/field_ui/src/Tests/ManageFieldsTest.php --- b/core/modules/field_ui/src/Tests/ManageFieldsTest.php +++ b/core/modules/field_ui/src/Tests/ManageFieldsTest.php @@ -273,21 +273,19 @@ $this->assertLinkByHref($field_edit_path); // Add two entries in the body. - $edit = array('title[0][value]' => 'Cardinality', 'body[0][value]' => 'Body 1', 'body[1][value]' => 'Body 2'); + $edit = ['title[0][value]' => 'Cardinality', 'body[0][value]' => 'Body 1', 'body[1][value]' => 'Body 2']; $this->drupalPostForm('node/add/article', $edit, 'Save'); $parts = explode('/', $this->getUrl()); $nid = array_pop($parts); // Assert that you can't set the cardinality to a lower number then the // highest delta of this field. - $edit = array( + $edit = [ 'cardinality' => 'number', 'cardinality_number' => 1, - ); + ]; $this->drupalPostForm($field_edit_path, $edit, t('Save field settings')); - $this->assertText('You can not set the cardinality lower than 2'); - $this->drupalPostForm('node/' . $nid . '/edit', array(), 'Save'); - $this->assertText('Body 2'); + $this->assertRaw(t('Cardinality must be higher than or equal to %minimum.', ['%minimum' => 2]), 'Correctly failed to set cardinality lower than highest delta.'); // Set to unlimited. $edit = array( @@ -299,18 +297,16 @@ $this->assertFieldByXPath("//select[@name='cardinality']", FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED); $this->assertFieldByXPath("//input[@name='cardinality_number']", 1); - $edit = array('title[0][value]' => 'Cardinality', 'body[0][value]' => 'Body 1', 'body[1][value]' => 'Body 2'); + $edit = ['title[0][value]' => 'Cardinality', 'body[0][value]' => 'Body 1', 'body[1][value]' => 'Body 2']; $this->drupalPostForm('node/' . $nid . '/edit', $edit, 'Save'); // Assert that you can't set the cardinality to a lower number then the // highest delta of this field. - $edit = array( + $edit = [ 'cardinality' => 'number', 'cardinality_number' => 1, - ); + ]; $this->drupalPostForm($field_edit_path, $edit, t('Save field settings')); - $this->assertText('You can not set the cardinality lower than 2'); - $this->drupalPostForm('node/' . $nid . '/edit', array(), 'Save'); - $this->assertText('Body 2'); + $this->assertRaw(t('Cardinality must be higher than or equal to %minimum.', ['%minimum' => 2]), 'Correctly failed to set cardinality lower than highest delta.'); } /**