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).
Comments
Comment #2
leksat commentedComment #3
slashrsm commentedThank you for your bug report and proposed patch. I was able to reproduce the problem.
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)
Comment #4
leksat commentedThanks @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.
Comment #6
slashrsm commentedCommitted. Thank you!