Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When a new node is being created we need a way to get the host entity.
I've created the following patch to address this.
Comment | File | Size | Author |
---|---|---|---|
#1 | field_collection_patch-2211667-1.patch | 621 bytes | gmercer |
Comments
Comment #1
gmercer CreditAttribution: gmercer commentedComment #2
jmuzz CreditAttribution: jmuzz commentedCan you explain why this is necessary? It's already putting the field collection item itself in the host's field when the host is new. The code related to that is enough to get them saved together.
Comment #3
tim.plunkettDirectly below that change is this line:
field_attach_form('field_collection_item', $field_collection_item, $element, $form_state, $language);
That runs a whole host of code, not all of which is passed the $element (where the entity is stored).
For example, passing the field collection item to an 'allowed_values_function' without this patch will not allow the function to introspect the field collection's host entity.
Consider the following code:
Comment #5
jmuzz CreditAttribution: jmuzz commentedMakes sense, thanks gmercer for the patch and tim.plunkett for laying that out for me.
I verified the patch is needed for the call to hostEntityBundle() to succeed in an allowed_values_function and committed.