Skip to content
Snippets Groups Projects
Commit 0c4546f3 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2686407 by andypost, aerozeppelin, darrick, mpdonadio: Datetime type...

Issue #2686407 by andypost, aerozeppelin, darrick, mpdonadio: Datetime type should be disabled on storage setting form if field has data
parent 7358f7a4
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -97,6 +97,7 @@ public function storageSettingsForm(array &$form, FormStateInterface $form_state
static::DATETIME_TYPE_DATETIME => t('Date and time'),
static::DATETIME_TYPE_DATE => t('Date only'),
),
'#disabled' => $has_data,
);
return $element;
......
......@@ -9,12 +9,12 @@
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\node\Entity\Node;
use Drupal\simpletest\WebTestBase;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests Datetime field functionality.
......@@ -804,6 +804,48 @@ function testInvalidField() {
$this->assertText('date is invalid', format_string('Invalid second value %time has been caught.', array('%time' => $time_value)));
}
/**
* Tests that 'Date' field storage setting form is disabled if field has data.
*/
public function testDateStorageSettings() {
// Create a test content type.
$this->drupalCreateContentType(['type' => 'date_content']);
// Create a field storage with settings to validate.
$field_name = Unicode::strtolower($this->randomMachineName());
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'node',
'type' => 'datetime',
'settings' => [
'datetime_type' => 'date',
],
]);
$field_storage->save();
$field = FieldConfig::create([
'field_storage' => $field_storage,
'field_name' => $field_name,
'bundle' => 'date_content',
]);
$field->save();
entity_get_form_display('node', 'date_content', 'default')
->setComponent($field_name, [
'type' => 'datetime_default',
])
->save();
$edit = [
'title[0][value]' => $this->randomString(),
'body[0][value]' => $this->randomString(),
$field_name . '[0][value][date]' => '2016-04-01',
];
$this->drupalPostForm('node/add/date_content', $edit, t('Save'));
$this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_name . '/storage');
$result = $this->xpath("//*[@id='edit-settings-datetime-type' and contains(@disabled, 'disabled')]");
$this->assertEqual(count($result), 1, "Changing datetime setting is disabled.");
$this->assertText('There is data for this field in the database. The field settings can no longer be changed.');
}
/**
* Renders a entity_test and sets the output in the internal browser.
*
......
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