From entity_browser/src/Plugin/Field/FieldWidget/EntityReference.php

      // Can be triggered by hidden target_id element or "Remove" button.
      if (end($trigger['#parents']) === 'target_id' || (end($trigger['#parents']) === 'remove_button')) {
        $is_relevant_submit = TRUE;

        // In case there are more instances of this widget on the same page we
        // need to check if submit came from this instance.
        $field_name_key = end($trigger['#parents']) === 'target_id' ? 2 : static::$deleteDepth + 1;
        $field_name_key = sizeof($trigger['#parents']) - $field_name_key;
        $is_relevant_submit &= ($trigger['#parents'][$field_name_key] === $this->fieldDefinition->getName());
      }

This code checks the triggered button key and the field name. It does not check if the triggered button parents are the same as the parents of the processing element.

An issue with that: there could be several fields on a form with the same name. For example, a paragraph field can hold several paragraphs of the same type (having the same fields).

CommentFileSizeAuthor
#3 interdiff.txt909 bytesslashrsm
#3 2745091_3.patch950 bytesslashrsm
#2 2745091-2.patch965 bytesleksat

Comments

Leksat created an issue. See original summary.

leksat’s picture

Status: Active » Needs review
StatusFileSize
new965 bytes
slashrsm’s picture

Issue tags: +D8Media
StatusFileSize
new950 bytes
new909 bytes

Thank you for your bug report and proposed patch. I was able to reproduce the problem.

+++ b/src/Plugin/Field/FieldWidget/EntityReference.php
@@ -305,7 +305,8 @@ class EntityReference extends WidgetBase implements ContainerFactoryPluginInterf
+          (array_slice($trigger['#parents'], 0, $field_name_key) == array_slice($element['#field_parents'], 0, $field_name_key));

This break the widget when used outside of the paragraphs. Enable entity_browser_example and try playing with fields on /node/add/entity_browser_test.

Attached patch seems to be working both in paragraphs and on a standalone field. Can you confirm it also works in your case? We should add a explanatory comment before committing this.

//Rant: We desperately need better test coverage! (obviously not scope of this issue)

leksat’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @slashrsm!

Your solution works even for my case - I have paragraphs that can hold another paragraphs :)

Not sure if I'm allowed to, but marking this as RTBC.

  • slashrsm committed 5a1f1dc on 8.x-1.x authored by Leksat
    Issue #2745091 by slashrsm, Leksat: Fix $is_relevant_submit calculation...
slashrsm’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Thank you!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.