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

Issue #3376692 by lauriii, mstrelan, quietone, acbramley, larowlan,...

Issue #3376692 by lauriii, mstrelan, quietone, acbramley, larowlan, smustgrave: Removed values in multi-value fields reappear

(cherry picked from commit 82b5bc08)
parent e4e192f7
No related branches found
No related tags found
20 merge requests!8376Drupal views: adding more granularity to the ‘use ajax’ functionality,!8300Issue #3443586 View area displays even when parent view has no results.,!7567Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7565Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7509Change label "Block description" to "Block type",!7344Issue #3292350 by O'Briat, KlemenDEV, hswong3i, smustgrave, quietone: Update...,!6922Issue #3412959 by quietone, smustgrave, longwave: Fix 12 'un' words,!6848Issue #3417553 by longwave: Remove withConsecutive() in CacheCollectorTest,!6720Revert "Issue #3358581 by pfrenssen, _tarik_, a.dmitriiev, smustgrave:...,!6560Update ClaroPreRender.php, confirming classes provided are in array format,!6528Issue #3414261 by catch: Add authenticated user umami performance tests,!6501Issue #3263668 by omkar-pd, Wim Leers, hooroomoo: Re-enable inline form errors...,!6354Draft: Issue #3380392 by phma: Updating language weight from the overview reverts label if translated,!6324Issue #3416723 by Ludo.R: Provide a "node type" views default argument,!6119Issue #3405704 by Spokje, longwave: symfony/psr-http-message-bridge major version bump,!5950Issue #3403653 by alexpott, longwave: Incorporate improvements to how contrib runs PHPStan to core,!5858Issue #3401971 by fjgarlin: Test-only job shouldn't require constant rebases...,!5716Draft: Issue #3401102 by Spokje, longwave, smustgrave: Nightwatch artifacts on GitLab not retained,!5674Transaction autocommit during shutdown relies on unreliable object destruction order,!5644Issue #3395563 by nireneko, marvil07, lauriii, borisson_, smustgrave, Wim...
Pipeline #34026 passed
+1
......@@ -68,8 +68,7 @@ public function form(FieldItemListInterface $items, array &$form, FormStateInter
$field_name = $this->fieldDefinition->getName();
$parents = $form['#parents'];
// Store field information in $form_state.
if (!static::getWidgetState($parents, $field_name, $form_state)) {
if (!$field_state = static::getWidgetState($parents, $field_name, $form_state)) {
$field_state = [
'items_count' => count($items),
'array_parents' => [],
......@@ -77,6 +76,13 @@ public function form(FieldItemListInterface $items, array &$form, FormStateInter
static::setWidgetState($parents, $field_name, $form_state, $field_state);
}
// Remove deleted items from the field item list.
if (isset($field_state['deleted_item']) && $items->get($field_state['deleted_item'])) {
$items->removeItem($field_state['deleted_item']);
unset($field_state['deleted_item']);
static::setWidgetState($parents, $field_name, $form_state, $field_state);
}
// Collect widget elements.
$elements = [];
......@@ -384,6 +390,8 @@ public static function deleteSubmit(&$form, FormStateInterface $form_state) {
$form_state->setUserInput($user_input);
}
$field_state['deleted_item'] = $delta;
unset($parent_element[$delta]);
NestedArray::setValue($form, $array_parents, $parent_element);
......
......@@ -150,6 +150,21 @@ public function testFieldMultipleValueWidget() {
// Assert that the wrapper exists and isn't nested.
$this->assertSession()->elementsCount('css', '[data-drupal-selector="edit-field-unlimited-wrapper"]', 1);
// Test removing items/values on saved entities resets to initial value.
$this->submitForm([], 'Save');
$field_2_remove_button->click();
$this->assertSession()->assertWaitOnAjaxRequest();
$field_1_remove_button->click();
$this->assertSession()->assertWaitOnAjaxRequest();
$field_0_remove_button->click();
$this->assertSession()->assertWaitOnAjaxRequest();
$add_more_button->click();
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertSame('', $field_0->getValue());
$add_more_button->click();
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertSame('', $field_1->getValue());
}
}
......@@ -77,10 +77,10 @@ protected function setUp(): void {
* Tests the correct user input mapping on complex fields.
*/
public function testCorrectUserInputMappingOnComplexFields() {
/** @var ContentEntityStorageInterface $storage */
/** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
$storage = $this->container->get('entity_type.manager')->getStorage($this->entityTypeId);
/** @var ContentEntityInterface $entity */
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $storage->create([
$this->fieldName => [
['shape' => 'rectangle', 'color' => 'green'],
......@@ -118,6 +118,24 @@ public function testCorrectUserInputMappingOnComplexFields() {
['shape' => 'circle', 'color' => 'blue'],
['shape' => 'rectangle', 'color' => 'green'],
], $entity->get($this->fieldName)->getValue());
$this->drupalGet($this->entityTypeId . '/manage/' . $entity->id() . '/edit');
// Delete one of the field items and ensure that the user input is mapped on
// the correct delta field items.
$edit = [
"$this->fieldName[0][_weight]" => 0,
"$this->fieldName[1][_weight]" => -1,
];
$this->submitForm($edit, "{$this->fieldName}_0_remove_button");
$this->submitForm([], 'Save');
$storage->resetCache([$entity->id()]);
$entity = $storage->load($entity->id());
$this->assertEquals([
['shape' => 'rectangle', 'color' => 'green'],
], $entity->get($this->fieldName)->getValue());
}
}
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