Needs work
Project:
Field collection
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
10 Apr 2012 at 10:38 UTC
Updated:
21 Oct 2019 at 07:30 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
skwashd commentedSorry I don't use the field collection module. Moving to the correct issue queue.
Comment #2
jmuzz commentedWould have to add support for the pathauto module to allow this to be configured at /admin/config/search/path/patterns . I think this is a good idea.
Comment #3
blake.thompson commentedHere's a patch that will add some basic support for field collections in pathauto. The patch adds a small module 'Field collection pathauto' with a new token that should update each field collection item when either it or its parent node is saved. The new module adds a dependency on the entity_token module.
An example token is [node:field-journal-entry:-1] but the chaining allows you to access a field (ex: [node:field-journal-entry:-1:field-title]).
In the original request's example, you should be able to alias
field-collection/field-products/62 to products/62 using token [node:field-products:-1:item-id]
It may not be the most ideal solution. It uses '-1' because I believe list tokens are required to use numeric deltas, but it does allow it to deal with each field collection item rather than being limited to a single field collection item.
Comment #4
osopolarSince there is support for the host entity token, this could be solved a bit different now. I don't think that an additional module would be necessary anymore, we could just use field_collection.pathauto.inc.
BTW: I was not able to get the url-path of the host node using the token [field_collection_item:host:node:url:path] until I changed the language handling for the host entity, see #1372652: Token support for host entity #91.
TODO: If the same field_collection is used on different entities or bundles we may need a path pattern for each. This could be done similar to language handling by prefixing field-name with $entity_type . '_' . $bundle . '_' and a custom version of pathauto_pattern_load_by_entity() searching for the best matching pattern. But IMHO this could be done in a follow up feature request.
Comment #5
osopolarComment #7
osopolarI have an issue on node add: When the field collection (with a path-alias including the host-node-path: [field_collection_item:host:node:url:path]/[field_collection_item:field-gallery-title]) is created on node add, then the added node gets cached without the fields. Fields are saved correctly, but won't show up until a cache clear. I tried a lot of stuff, i.e. clone the entity before passing to token replace or clearing caches like below, but nothing didn't work yet. I still need to debug more, to find the exact cause for the problem.
Any ideas how to clear the host entity cache after creation of the path alias?
Comment #8
osopolarAnother problem I noticed is, that url aliases are created with language=und, which could result in duplicated aliases if the alias already exists for a language (i.e. language "de"). In my case the field collection item page could not be called, as the other content with the same url got loaded.
Should we set the host item language for the url-alias language (to prevent language=und), like that:?Edit: This is a path-auto issue: #2067191: pathauto handles language-neutral aliases wrong resulting in duplicates
Comment #9
iKristjan commentedHere's my patch for a more complete Pathauto support for field collection items.
Patterns can be configured via regular Pathauto UI and you can have different patterns per every field collection. When locale is enabled you can have different patterns per language (like the Node and Taxonomy pattern support). The language is host entity language (usually it's node's), but I made sure it supports nested field collections.
NB! When creating patterns you would want to enable the 'Entity tokens' module to have all the field tokens for the field collection item. Host entity tokens will be there by default.
Comment #10
osopolar@iKristjan: Thanks for the patch, I haven't tested jet. Do you expirience similar problems that I described in #7 (my pattern looks like: [field_collection_item:host:node:url:path]/[field_collection_item:field-gallery-title])?
Comment #11
thulenb commentedThe patch works well for me. I only have the problem that the patterns only work for my first language but not for the second language. Does somebody else have this problem?
Comment #12
chris matthews commentedThe 3 year old patch in #9 does not apply to the latest 7.x-1.x dev snapshot and may be too old to reroll, but I went ahead and tagged the issue accordingly.
Comment #13
osopolarI have the 4 years old patch from #5 still in use. I did not check the patch from #9.
Comment #15
ram4nd commentedI committed #5, but there is work to be done, so I'll leave the issue opened.