Skip to content
Snippets Groups Projects
Commit 1c1e9111 authored by catch's avatar catch
Browse files

Issue #1140188 by torotil, NROTC_Webmaster, cam8001, agi.novanta, jhedstrom,...

Issue #1140188 by torotil, NROTC_Webmaster, cam8001, agi.novanta, jhedstrom, lnunesbr, kathyh: Fatal errors during or after adding default values for autocomplete widgets
parent fc45b90e
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
......@@ -104,7 +104,13 @@ public function defaultValuesFormSubmit(array $element, array &$form, FormStateI
// Convert numeric IDs to UUIDs to ensure config deployability.
$ids = array();
foreach ($default_value as $delta => $properties) {
$ids[] = $properties['target_id'];
if (isset($properties['entity']) && $properties['entity']->isNew()) {
// This may be a newly created term.
$properties['entity']->save();
$default_value[$delta]['target_id'] = $properties['entity']->id();
unset($default_value[$delta]['entity']);
}
$ids[] = $default_value[$delta]['target_id'];
}
$entities = \Drupal::entityManager()
->getStorage($this->getSetting('target_type'))
......
......@@ -297,6 +297,32 @@ public function testFieldAdminHandler() {
);
$this->drupalPostForm('node/add/' . $this->type, $edit, t('Save'));
$this->assertLink($node1->getTitle());
// Tests adding default values to autocomplete widgets.
Vocabulary::create(array('vid' => 'tags', 'name' => 'tags'))->save();
$taxonomy_term_field_name = $this->createEntityReferenceField('taxonomy_term', 'tags');
$field_path = 'node.' . $this->type . '.field_' . $taxonomy_term_field_name;
$this->drupalGet($bundle_path . '/fields/' . $field_path . '/storage');
$edit = [
'cardinality' => -1,
];
$this->drupalPostForm(NULL, $edit, t('Save field settings'));
$this->drupalGet($bundle_path . '/fields/' . $field_path);
$term_name = $this->randomString();
$edit = [
// This must be set before new entities will be auto-created.
'settings[handler_settings][auto_create]' => 1,
];
$this->drupalPostForm(NULL, $edit, t('Save settings'));
$this->drupalGet($bundle_path . '/fields/' . $field_path);
$edit = [
// A term that doesn't yet exist.
'default_value_input[field_' . $taxonomy_term_field_name . '][0][target_id]' => $term_name,
];
$this->drupalPostForm(NULL, $edit, t('Save settings'));
// The term should now exist.
$term = taxonomy_term_load_multiple_by_name($term_name, 'tags')[1];
$this->assertIdentical(1, count($term), 'Taxonomy term was auto created when set as field default.');
}
/**
......
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