Skip to content
Snippets Groups Projects
Commit 84efb814 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 b6eb5897
No related branches found
No related tags found
11 merge requests!8506Draft: Issue #3456536 by ibrahim tameme,!5646Issue #3350972 by nod_: [random test failure]...,!5600Issue #3350972 by nod_: [random test failure]...,!5343Issue #3305066 by quietone, Rename RedirectLeadingSlashesSubscriber,!3603#ISSUE 3346218 Add a different message on edit comment,!3555Issue #2473873: Views entity operations lack cacheability support, resulting in incorrect dropbuttons,!3494Issue #3327018 by Spokje, longwave, xjm, mondrake: Update PHPStan to 1.9.3 and...,!3410Issue #3340128: UserLoginForm::submitForm has some dead code,!3389Issue #3325184 by Spokje, andypost, xjm, smustgrave: $this->configFactory is...,!3381Issue #3332363: Refactor Claro's menus-and-lists stylesheet,!3307Issue #3326193: CKEditor 5 can grow past the viewport when there is a lot of content
......@@ -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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment