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

Issue #3373947: Saving the settings UI removes field mapping

parent 0b07588d
No related branches found
Tags 8.x-1.0
1 merge request!28Issue #3373947: Saving the settings UI removes field mapping
......@@ -295,9 +295,9 @@ class SettingsForm extends ConfigFormBase implements TrustedCallbackInterface {
$entity_types = $config->get('entity_types');
foreach ($form_state->getValue('entity_types') as $entity_type_id => $entity_type_info) {
if ($entity_type_info['enabled']) {
// If the entity type is already set then copy the entity reference fields
// if any are set.
$entity_types[$entity_type_id] = $existing_entity_types[$entity_type_id] ?? ['view_mode' => $entity_type_info['view_mode']];
// If the entity type is already set ensure we do not overwrite any
// fields set.
$entity_types[$entity_type_id]['view_mode'] = $entity_type_info['view_mode'];
}
else {
unset($entity_types[$entity_type_id]);
......
......@@ -209,6 +209,32 @@ class VGWortTest extends BrowserTestBase {
public function testAddParticipantsReference() : void {
$this->createEntityReferenceField('node', 'article', 'field_participants', 'Participants', 'user');
_vgwort_add_entity_reference_to_participant_map('node', 'field_participants');
$config = $this->config('vgwort.settings');
$this->assertSame(['field_participants'], $config->get('entity_types.node.fields'));
$this->assertSame('full', $config->get('entity_types.node.view_mode'));
// Ensure that using the UI does not overwrite this information.
// Module settings.
$this->drupalLogin($this->createUser([], 'site admin', TRUE));
$this->drupalGet('admin/config/system/vgwort');
$this->assertSession()->fieldExists('username')->setValue('aaaBBB');
$this->assertSession()->fieldExists('password')->setValue('t3st');
$this->assertSession()->fieldExists('publisher_id')->setValue('1234567');
$this->assertSession()->fieldExists('domain')->setValue('example.com');
// Ensure only publishable entity types with canonical links are listed.
$options = $this->assertSession()->elementExists('css', '#edit-entity-types')->findAll('css', 'input');
$this->assertCount(2, $options);
$this->assertTrue($this->assertSession()->fieldExists('entity_types[node][enabled]')->isChecked());
$this->assertFalse($this->assertSession()->fieldExists('entity_types[taxonomy_term][enabled]')->isChecked());
$this->assertSession()->fieldExists('entity_types[taxonomy_term][enabled]')->check();
$this->assertSession()->fieldExists('entity_types[node][view_mode]')->selectOption('search_index');
$this->submitForm([], 'Save configuration');
$this->assertSession()->pageTextContains('The configuration options have been saved.');
$config = $this->config('vgwort.settings');
$this->assertSame(['field_participants'], $config->get('entity_types.node.fields'));
$this->assertSame('search_index', $config->get('entity_types.node.view_mode'));
}
}
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