Commit 01d9799d authored by alexpott's avatar alexpott

Issue #2354685 by amateescu, tstoeckler, derhasi: Fatal Error on re-saving...

Issue #2354685 by amateescu, tstoeckler, derhasi: Fatal Error on re-saving required EntityReference field setting
parent c902ba68
......@@ -334,6 +334,9 @@ public function defaultValuesFormValidate(array $element, array &$form, FormStat
// Extract the submitted value, and validate it.
$widget = $this->defaultValueWidget($form_state);
$widget->extractFormValues($this, $element, $form_state);
// Force a non-required field definition.
// @see self::defaultValueWidget().
$this->definition->required = FALSE;
$violations = $this->validate();
// Assign reported errors to the correct form element.
......
......@@ -103,11 +103,18 @@ public function testFieldAdminHandler() {
// Third step: confirm.
$this->drupalPostForm(NULL, array(
'field[required]' => '1',
'field[settings][handler_settings][target_bundles][' . key($bundles) . ']' => key($bundles),
), t('Save settings'));
// Check that the field appears in the overview form.
$this->assertFieldByXPath('//table[@id="field-overview"]//tr[@id="field-test"]/td[1]', 'Test label', 'Field was created and appears in the overview page.');
// Check that the field settings form can be submitted again, even when the
// field is required.
// The first 'Edit' link is for the Body field.
$this->clickLink(t('Edit'), 1);
$this->drupalPostForm(NULL, array(), t('Save settings'));
}
......
......@@ -359,6 +359,24 @@ function testDefaultValue() {
$field = FieldConfig::loadByName('node', $this->type, $field_name);
$this->assertEqual($field->default_value, NULL, 'The default value was correctly saved.');
// Check that the default value can be empty when the field is marked as
// required and can store unlimited values.
$field_storage = FieldStorageConfig::loadByName('node', $field_name);
$field_storage->cardinality = FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED;
$field_storage->save();
$this->drupalGet($admin_path);
$edit = array(
'field[required]' => 1,
);
$this->drupalPostForm(NULL, $edit, t('Save settings'));
$this->drupalGet($admin_path);
$this->drupalPostForm(NULL, array(), t('Save settings'));
$this->assertText("Saved $field_name configuration", 'The form was successfully submitted.');
$field = FieldConfig::loadByName('node', $this->type, $field_name);
$this->assertEqual($field->default_value, NULL, 'The default value was correctly saved.');
// Check that the default widget is used when the field is hidden.
entity_get_form_display($field->entity_type, $field->bundle, 'default')
->removeComponent($field_name)->save();
......
Markdown is supported
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