The helper function field_collection_field_formatter_links() assumes that the field it's rendering is on an entity which has already been created (and not 'brand new'). As such if I render a Field collection field on a node which is as-of-yet unsaved (i.e. without nid), then an "Add" link will get rendered (if configured to do so) which links to a broken page.

OK, this sounds like a very edge case - however you bump right into it with the following recipe:

1. Enable field_collection module
2. Create a field collection field - perhaps with Title, image, description and link sub-fields - putting it on a node type, say Page.
3. Use the Field extra widgets module and choose the "Read only" form widget for your field collection field (on Page node type Manage Fields UI)
4. Use the Field Collection Table module and configure your form widget to render the values of the field as a nice table. (Yay - a nice looking alternative to the nested-field-collection-embedded-subforms-of-doom =P)
5. This all works great, except we get our broken "Add" link rendered on the node/add page, I go to a URL which clearly assumes that there will always be a nid on the entity, it looks something like:


A conspicuously missing 'nid' value there.

There are two possible solutions here I think:

1. (Harder) Provide an alternative menu callback (which doesn't rely on an entity_id) which allows creating temporary field collection item values for use in as-of-yet-unsaved-brand-new-entity forms. This is, in principle, possible because the embedded widget allows creating values on brand new entities.

2. (Simpler) Just hide the darn Add link on entity creation forms, and only show it on the edit forms.

Patch for solution 2 to follow. If anyone wants to submit a patch for solution 1 they are welcome!

#3 field_collection-broken-add-1946474-3.patch1010 byteskristofferwiklund
PASSED: [[SimpleTest]]: [MySQL] 163 pass(es). View
#1 field_collection-1946474-01.patch1.95 KBjamsilver
PASSED: [[SimpleTest]]: [MySQL] 132 pass(es). View
Members fund testing for the Drupal project. Drupal Association Learn more


jamsilver’s picture

Assigned: jamsilver » Unassigned
Status: Needs work » Needs review
1.95 KB
PASSED: [[SimpleTest]]: [MySQL] 132 pass(es). View

Patch attached for the simpler solution of just hiding the Add link on entity creation forms.

jamsilver’s picture

If anyone is interested in my above recipe, the following drush makefile snippet lets you know the sort of patches you need to be running to get it working at the moment:

projects[field_collection][subdir] = "contrib"
projects[field_collection][version] = "1.0-beta5"
projects[field_collection][patch][] = ""

projects[field_collection_table][subdir] = "contrib"
projects[field_collection_table][version] = "1.0-beta1"
projects[field_collection_table][patch][] = ""
projects[field_collection_table][patch][] = ""
projects[field_collection_table][patch][] = ""
projects[field_collection_table][patch][] = ""

Unfortunately field_collection_table is a little worse for wear these days, so you may well need other patches too from the queue!

kristofferwiklund’s picture

Version: 7.x-1.0-beta5 » 7.x-1.x-dev
1010 bytes
PASSED: [[SimpleTest]]: [MySQL] 163 pass(es). View

I have confirmed the problem with Field extra widget. But the patch needed to be re-rolled against 7.x-1.x-dev, which I did.

I don't think there is any possibility for solution 1, without any type of ajax solution as the node will never be saved between page loads. And a ajax solution is the embedded widget already in the module.