i am using Drupal 7 and i have created a field collection for products but when i am trying to visit collection items it shows _{host}/nl/field-collection/field-products/62_ i want to replace _field-collection/field-products_ with _products_ how can i do it? Thankz in advance

Comments

skwashd’s picture

Project: URL Alias » Field collection
Assigned: krunal.goswami » Unassigned
Category: feature » support

Sorry I don't use the field collection module. Moving to the correct issue queue.

jmuzz’s picture

Title: Drupal 7 URL Rewrite » Add pathauto support
Category: Support request » Feature request
Issue summary: View changes
Priority: Major » Normal

Would 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.

blake.thompson’s picture

Here'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.

osopolar’s picture

Status: Active » Needs review

Since 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.

osopolar’s picture

The last submitted patch, 3: field_collection-pathauto_support-1525352-3.patch, failed testing.

osopolar’s picture

I 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.

entity_get_controller($host_entity_type)->resetCache($host_entity);
entity_get_controller($entity->entityType())->resetCache(array($entity->item_id));

Any ideas how to clear the host entity cache after creation of the path alias?

osopolar’s picture

Another 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

iKristjan’s picture

Here'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.

osopolar’s picture

@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])?

thulenb’s picture

The 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?

chris matthews’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll, +Needs rework

The 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.

Checking patch field_collection.module...
error: while searching for:
    return $map;
  }
}

error: patch failed: field_collection.module:1505
error: field_collection.module: patch does not apply
Checking patch field_collection.pathauto.inc...
osopolar’s picture

I have the 4 years old patch from #5 still in use. I did not check the patch from #9.

  • ram4nd committed f59d4a5 on 7.x-1.x authored by osopolar
    Issue #1525352 by osopolar, iKristjan, blake.thompson: Add pathauto...
ram4nd’s picture

I committed #5, but there is work to be done, so I'll leave the issue opened.

  • ram4nd committed 1f3b842 on 7.x-1.x authored by osopolar
    Issue #1525352 by osopolar, iKristjan, blake.thompson: Add pathauto...