Problem/Motivation
paragraphs_field_widget_form_build()
is executed for every paragraphs field. For a nested paragraph, it's executed for different entity types. First on a node
, then on a paragraphs_item
. field_form_get_state()
seems to work on the entire form, not the 'current part' (the $element
). This means a sub paragraph element can change the field state to paragraphs_item
for the next field item in the node
.
Horrible explanation, sorry. Specifically, my problem:
- paragraph 1 (delta 0 in field X) runs on 'node'
- paragraph 2 (delta 1 in field X) runs on 'node'
- paragraph 2 loads a paragraph field Y with 1 item
- paragraph 3 (delta 0 on field Y) runs on 'paragraphs_item'
- paragraph 4 (delta 2 in field X) runs on 'paragraphs_item', because the last field state was a 'paragraphs_item', but the current field is a 'node' field, so this is very wrong
It dies on
$paragraph_item->setHostEntity($field_state['instance']['entity_type'], $element['#entity'], $langcode, FALSE);
because $field_state['instance']['entity_type']
is wrong.
Proposed resolution
Don't use $field_state
to find the current entity type. You don't use it to find the current entity either. The current entity in $element is correct, so use $element to find the current entity type too:
$paragraph_item->setHostEntity($element['#entity_type'], $element['#entity'], $langcode, FALSE);
Remaining tasks
Change 1 line. Patch later.
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#2 | paragraphs-2852861-2.patch | 1.14 KB | rudiedirkx |
Comments
Comment #2
rudiedirkx CreditAttribution: rudiedirkx at ezCompany commentedPatch against 7.x-1.0-rc4, not dev.
Comment #3
rudiedirkx CreditAttribution: rudiedirkx at ezCompany commentedComment #4
ericclaeren CreditAttribution: ericclaeren at ezCompany commentedPatch against 7.x-1.0-rc5, not dev.Comment #5
ericclaeren CreditAttribution: ericclaeren at ezCompany commentedBloody... My patch paragraphs-2852861-4.patch was ment for another issue. Wrong browser tab. My apologies.
Comment #6
jstollerIt looks like this was fixed in one of the recent commits to dev.