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:

  1. paragraph 1 (delta 0 in field X) runs on 'node'
  2. paragraph 2 (delta 1 in field X) runs on 'node'
  3. paragraph 2 loads a paragraph field Y with 1 item
  4. paragraph 3 (delta 0 on field Y) runs on 'paragraphs_item'
  5. 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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rudiedirkx created an issue. See original summary.

rudiedirkx’s picture

FileSize
1.14 KB

Patch against 7.x-1.0-rc4, not dev.

rudiedirkx’s picture

ericclaeren’s picture

Patch against 7.x-1.0-rc5, not dev.

ericclaeren’s picture

Bloody... My patch paragraphs-2852861-4.patch was ment for another issue. Wrong browser tab. My apologies.

jstoller’s picture

Status: Active » Closed (outdated)

It looks like this was fixed in one of the recent commits to dev.