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:

field-collection/field-driver/add/node/?destination=node/add/page

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!

Files: 
CommentFileSizeAuthor
#1 field_collection-1946474-01.patch1.95 KBjamsilver
PASSED: [[SimpleTest]]: [MySQL] 132 pass(es).
[ View ]

Comments

Assigned:jamsilver» Unassigned
Status:Needs work» Needs review
StatusFileSize
new1.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.

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][] = "http://drupal.org/files/field_collection-1946474-01.patch"
projects[field_collection_table][subdir] = "contrib"
projects[field_collection_table][version] = "1.0-beta1"
projects[field_collection_table][patch][] = "http://drupal.org/files/view_mode_issues-1426806-7.patch"
projects[field_collection_table][patch][] = "http://drupal.org/files/field_collection_table-1815496-2-fix_malformed_table.patch"
projects[field_collection_table][patch][] = "http://drupal.org/files/field-collection-table-1877218.patch"
projects[field_collection_table][patch][] = "http://drupal.org/files/field_collection_table-1459836-access-attribute.patch"

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