Commit d5810104 authored by fenstrat's avatar fenstrat Committed by fenstrat

Issue #2925436 by fenstrat, acbramley: Reordering multi valued block fields...

Issue #2925436 by fenstrat, acbramley: Reordering multi valued block fields mixes up block id and settings for moved items once entity is saved
parent 3dc43bd8
......@@ -266,7 +266,7 @@ class BlockFieldWidget extends WidgetBase implements ContainerFactoryPluginInter
// Execute block submit configuration in order to transform the form
// values into block configuration.
if (!empty($value['plugin_id']) && !empty($value['settings']) && $block = $this->blockManager->createInstance($value['plugin_id'])) {
$elements = &$form[$field_name]['widget'][$delta]['settings'];
$elements = &$form[$field_name]['widget'][$value['_original_delta']]['settings'];
$subform_state = SubformState::createForSubform($elements, $form_state->getCompleteForm(), $form_state);
$block->submitConfigurationForm($elements, $subform_state);
$value['settings'] = $block->getConfiguration();
......
......@@ -74,6 +74,20 @@ class BlockFieldTest extends BrowserTestBase {
$assert->elementContains('css', $selector, '<h2>The time is...</h2>');
$assert->responseMatches('/\d\d:\d\d:\d\d/');
// Check adjusting block weights maintains plugin settings.
$this->drupalGet($node->toUrl('edit-form'));
// Switch the position of block 1 and 2.
$this->drupalPostForm(NULL, [
'field_block_field_test[0][_weight]' => 1,
'field_block_field_test[1][_weight]' => 0,
], $this->t('Save'));
$this->drupalGet($node->toUrl('edit-form'));
// Plugin id and label should be switched.
$assert->fieldValueEquals('field_block_field_test[0][plugin_id]', 'block_field_test_content');
$assert->fieldValueEquals('field_block_field_test[0][settings][label]', 'Block field test content');
$assert->fieldValueEquals('field_block_field_test[1][plugin_id]', 'block_field_test_authenticated');
$assert->fieldValueEquals('field_block_field_test[1][settings][label]', 'You are logged in as...');
// Create a block_field_test node.
$block_node = $this->drupalCreateNode([
'type' => 'block_field_test',
......
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