Commit 0891913c authored by Ben Mullins's avatar Ben Mullins
Browse files

Issue #2895124 by xjm, lauriii, joaopauloc.dev, Berdir: Field storage settings...

Issue #2895124 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
parent be7d65ec
......@@ -919,7 +919,6 @@ public function testDateStorageSettings() {
$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.');
}
}
......@@ -1417,7 +1417,6 @@ public function testDateStorageSettings() {
$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.');
}
}
......@@ -68,13 +68,7 @@ public function form(array $form, FormStateInterface $form_state) {
$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 @@ public function validateCardinality(array &$element, FormStateInterface $form_st
->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')]));
}
}
}
......
......@@ -313,7 +313,7 @@ public function cardinalitySettings() {
];
$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 @@ public function cardinalitySettings() {
];
$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 @@ public function cardinalitySettings() {
];
$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 @@ public function cardinalitySettings() {
];
$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,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment