Issue by xjm, lauriii, joaopauloc.dev, Berdir: Field storage settings give a scary red warning that they can't be changed when the cardinality is the only thing with restrictions

merge-requests/3367/head
bnjmnm 2023-01-24 12:10:34 -05:00
parent b6eb5897d7
commit 84efb81423
4 changed files with 7 additions and 15 deletions
core/modules
datetime/tests/src/Functional
datetime_range/tests/src/Functional

View File

@ -919,7 +919,6 @@ class DateTimeFieldTest extends DateTestBase {
$this->submitForm($edit, 'Save');
$this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_name . '/storage');
$this->assertSession()->elementsCount('xpath', "//*[@id='edit-settings-datetime-type' and contains(@disabled, 'disabled')]", 1);
$this->assertSession()->pageTextContains('There is data for this field in the database. The field settings can no longer be changed.');
}
}

View File

@ -1417,7 +1417,6 @@ class DateRangeFieldTest extends DateTestBase {
$this->submitForm($edit, 'Save');
$this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_name . '/storage');
$this->assertSession()->elementsCount('xpath', "//*[@id='edit-settings-datetime-type' and contains(@disabled, 'disabled')]", 1);
$this->assertSession()->pageTextContains('There is data for this field in the database. The field settings can no longer be changed.');
}
}

View File

@ -68,13 +68,7 @@ class FieldStorageConfigEditForm extends EntityForm {
$field_label = $form_state->get('field_config')->label();
$form['#title'] = $field_label;
$form['#prefix'] = '<p>' . $this->t('These settings apply to the %field field everywhere it is used. These settings impact the way that data is stored in the database and cannot be changed once data has been created.', ['%field' => $field_label]) . '</p>';
// See if data already exists for this field.
// If so, prevent changes to the field settings.
if ($this->entity->hasData()) {
$form['#prefix'] = '<div class="messages messages--error">' . $this->t('There is data for this field in the database. The field settings can no longer be changed.') . '</div>' . $form['#prefix'];
}
$form['#prefix'] = '<p>' . $this->t('These settings apply to the %field field everywhere it is used. Some also impact the way that data is stored and cannot be changed once data has been created.', ['%field' => $field_label]) . '</p>';
// Add settings provided by the field module. The field module is
// responsible for not returning settings that cannot be changed if
@ -203,7 +197,7 @@ class FieldStorageConfigEditForm extends EntityForm {
->count()
->execute();
if ($entities_with_higher_delta) {
$form_state->setError($element['cardinality_number'], $this->formatPlural($entities_with_higher_delta, 'There is @count entity with @delta or more values in this field.', 'There are @count entities with @delta or more values in this field.', ['@delta' => $form_state->getValue('cardinality') + 1]));
$form_state->setError($element['cardinality_number'], $this->formatPlural($entities_with_higher_delta, 'There is @count entity with @delta or more values in this field, so the allowed number of values cannot be set to @allowed.', 'There are @count entities with @delta or more values in this field, so the allowed number of values cannot be set to @allowed.', ['@delta' => $form_state->getValue('cardinality') + 1, '@allowed' => $form_state->getValue('cardinality')]));
}
}
}

View File

@ -313,7 +313,7 @@ class ManageFieldsFunctionalTest extends BrowserTestBase {
];
$this->drupalGet($field_edit_path);
$this->submitForm($edit, 'Save field settings');
$this->assertSession()->pageTextContains("There is 1 entity with 2 or more values in this field.");
$this->assertSession()->pageTextContains("There is 1 entity with 2 or more values in this field");
// Create a second entity with three values.
$edit = ['title[0][value]' => 'Cardinality 3', 'body[0][value]' => 'Body 1', 'body[1][value]' => 'Body 2', 'body[2][value]' => 'Body 3'];
@ -339,7 +339,7 @@ class ManageFieldsFunctionalTest extends BrowserTestBase {
];
$this->drupalGet($field_edit_path);
$this->submitForm($edit, 'Save field settings');
$this->assertSession()->pageTextContains("There are 2 entities with 2 or more values in this field.");
$this->assertSession()->pageTextContains("There are 2 entities with 2 or more values in this field");
$edit = [
'cardinality' => 'number',
@ -347,7 +347,7 @@ class ManageFieldsFunctionalTest extends BrowserTestBase {
];
$this->drupalGet($field_edit_path);
$this->submitForm($edit, 'Save field settings');
$this->assertSession()->pageTextContains("There is 1 entity with 3 or more values in this field.");
$this->assertSession()->pageTextContains("There is 1 entity with 3 or more values in this field");
$edit = [
'cardinality' => 'number',
@ -385,14 +385,14 @@ class ManageFieldsFunctionalTest extends BrowserTestBase {
];
$this->drupalGet($field_edit_path);
$this->submitForm($edit, 'Save field settings');
$this->assertSession()->pageTextContains("There are 2 entities with 3 or more values in this field.");
$this->assertSession()->pageTextContains("There are 2 entities with 3 or more values in this field");
$edit = [
'cardinality' => 'number',
'cardinality_number' => 3,
];
$this->drupalGet($field_edit_path);
$this->submitForm($edit, 'Save field settings');
$this->assertSession()->pageTextContains("There is 1 entity with 4 or more values in this field.");
$this->assertSession()->pageTextContains("There is 1 entity with 4 or more values in this field");
$edit = [
'cardinality' => 'number',
'cardinality_number' => 4,