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.
Instead of only supporting special entities (nodes, users, terms) pathauto should work for every entity that is accessible via a URL. Users should be able to select any entity type and bundle to specify patterns for them, same for the bulk update. Entity meta information can be retrieved by entity_get_info(). The Entity API provides additional meta information and tokens that could be used in the URL.
Example use case: Profile2 entities.
An alternative is using https://www.drupal.org/project/pathauto_entity
Comment | File | Size | Author |
---|---|---|---|
#28 | my_entity.pathauto.inc_.txt | 4.19 KB | acbramley |
#10 | generalpathauto.png | 23.49 KB | Jax |
#9 | generalpathauto.png | 23.56 KB | Jax |
Comments
Comment #1
Dave ReidYes this is definitely something that I've wanted to work on in a 7.x-2.x branch but my focus has been getting things stable for a 1.0 so I hadn't yet created an issue for it. The big blocker I will add with operating on an all possible entities is you have to somehow determine which entities actually get path aliases. Obviously my first through is you can check if 'uri callback' is provided in hook_entity_info() since this will give us a reliable 'source' path. But then think about the following entities which actually do have an uri callback:
- Comments: URIs redirect to node/[node:nid] pages - there are no individual 'view' pages for comments
- Commerce products: URIs are not user-visible, by default they link to administration URLs for the products. Aliasing these paths would not make any sense.
We either need to enforce the pattern of 'uri callback' being a public-visible URI and nothing else, or we have to add workarounds for specific entity types, which sucks. I'm encountering this same problem in several other modules like Metatags and Redirect API.
For now leaving this as postponed.
Related:
#273104: Using "progressive disclosure" for alias patterns
#681022: Split out entity alias generation into their own functions
Comment #2
Dave ReidAlso see core issue #1332058: Need a way to distinguish "public/final" URIs for entities from admin and redirected ones
Comment #3
Damien Tournoud CreditAttribution: Damien Tournoud commentedAlso see http://drupal.org/sandbox/damz/1332096 for a quick-and-dirty workaround.
Comment #4
Dave ReidComment #5
Jax CreditAttribution: Jax commentedIt should work with more than just entity types. I think it would be possible to make it work with any internal URL. Even ones from views.
The current pattern screen assumes internal URLs for each of the entity types it currently supports:
It could be replaced by a more generic form where one could:
Pathauto could then in the hook_entity_X hooks check for these configurations and act accordingly.
This would allow me for example to make a view with a path view-news/% that shows all the news for a specific term and map it to:
news/[term:vocabulary]/[term:name]
For sites with one language this might not seem interesting since you can just use news as the path for the view but once this integrates with i18n it becomes very powerful. Currently we kinda hardcode this often.
Am gonna work on that...
Comment #6
Dave ReidYes, the plan is to make Pathauto 7.x-2.x more entity-generic. Please see the sandbox posted in #3 which gets us part of the way there but doesn't work for bulk generation.
Comment #7
Ale.bcn CreditAttribution: Ale.bcn commentedsubscribing :)
Comment #8
klausiStop subscribing, start following: http://drupal.org/node/1306444
Comment #9
Jax CreditAttribution: Jax commentedSince we were discussing this at work today, again I made a small mock-up of how I see the interface. The second line means:
Generate a Dutch alias for all the (Dutch) terms in the 'News categories' vocabulary.
If you have in the news categories the following terms (with tid):
* interior (2)
* abroad (3)
It will generate the aliases:
view-news/2 => nieuws/interior
view-news/3 => nieuws/abroad
This would save us so much trouble....
Comment #10
Jax CreditAttribution: Jax commentedThe previous mock-up is missing a text field...
Comment #11
Ale.bcn CreditAttribution: Ale.bcn commentedHi Damien,
today I've tried to download your module and i got:
$ git clone http://git.drupal.org/sandbox/damz/1332096.git pathauto_integration_for_all_entity_types
Cloning into 'pathauto_integration_for_all_entity_types'...
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
warning: remote HEAD refers to nonexistent ref, unable to checkout.
:(
Comment #12
klausi@Ale.bcn: see http://drupal.org/project/1332096/git-instructions
Comment #13
Ale.bcn CreditAttribution: Ale.bcn commentedHi Klausi,
hehehe thanks!
Comment #14
aufumy CreditAttribution: aufumy commentedThis works for me, Damiens pathauto entity module, provided an interface for customizing profile2 pathauto patterns.
Also, enabling entity tokens module, exposed the profile entity fields as tokens.
Comment #15
kevinquillen CreditAttribution: kevinquillen commentedBe aware of this issue though:
#1540010: pathauto_entity_entity_insert causes file uploads to fail with File Entity
Comment #16
Jax CreditAttribution: Jax commentedJust FYI, I've implemented the module for which I made a mock up since we needed it:
http://drupal.org/sandbox/jax/1572908
Comment #17
Oceanman CreditAttribution: Oceanman commentedJax, how does your sandbox project compare to Damiens' sandbox?
Are you using this on a live site?
Having custom urls for user profiles is the feature I want most from pathauto. Is that working for you?
Comment #18
Jax CreditAttribution: Jax commented@Oceanman: I've not used Damien's module but the main difference is, I guess, that mine allows to generate aliases for generic paths which means you can create aliases for any view you have. As I understand from the thread Damien's one is couple with entities so it only allows to generate aliases for entities which define their URL in hook_entity_info().
We're actually already using my module for a new feature of a site but it's not online yet and I'm sure we will be using it more since it's really useful in multilingual scenario's.
Comment #19
Syd Barrett CreditAttribution: Syd Barrett commentedHi guys,
has anyone used Damien's or Jax's code? What's your feedback?
Comment #20
kevinquillen CreditAttribution: kevinquillen commentedPathauto Entity has worked fine for me other than #15.
Comment #21
Anonymous (not verified) CreditAttribution: Anonymous commentedSince Entities were presented in D7 this should be at least a "major" priority.
Comment #22
Barto.G CreditAttribution: Barto.G commentedWell i have tried this module http://drupal.org/sandbox/damz/1332096 and the patterns shows up but it does not generate an alias.
Then i have tried this module http://drupal.org/sandbox/jax/1572908 and i am not sure what the router item should be... Any advice please.
Tks
Comment #23
Jax CreditAttribution: Jax commented@guizmo: The router item should be something like taxonomy/% or my-view/%
Comment #24
Barto.G CreditAttribution: Barto.G commented@jax thanks,
Works perfectly !
Comment #25
Anonymous (not verified) CreditAttribution: Anonymous commentedAny development yet?
Comment #26
kevinquillen CreditAttribution: kevinquillen commentedI am still using #3 and #15 to achieve this.
Comment #27
Anonymous (not verified) CreditAttribution: Anonymous commentedI made some changes to the http://drupal.org/sandbox/damz/1332096 version which adds:
Bundle support, URL Path settings form override on entity edit form and other things.
The URL path settings form is added via a hook.
Sorry for more then likely not submitting this correctly but if there is another way to submit this that helps out please let me know. Here is the most recent updates:
http://drupal.org/node/1947226#comment-7199476
Comment #28
acbramley CreditAttribution: acbramley commentedIt's already possible to implement aliases for custom entity types using hook_pathauto, hook_path_alias_types, and various callbacks defined in hook_pathauto. See the sample file for how I added it to my custom entity. I then added the following hooks to my module file:
Hope this helps someone :)
Note: I now see that this is what the sandbox does but more generically, nice!
Comment #29
solquimpo CreditAttribution: solquimpo commentedHi there. I created and attached a patch containing bpcarlsen's updates (works great, thank you) on:
https://drupal.org/node/1947226#comment-7707665
and use drush make to automatically checkout and patch the sandbox project:
drush make -y --no-core --contrib-destination=sites/all build.make --projects=pathauto_entity
and in build.make, I added:
Thanks to all who worked/are working on this module. It is very useful. :)
Comment #30
acbramley CreditAttribution: acbramley commented+1 to get this promoted to a full project, then maybe merge in at a later date?
Comment #31
jsibley CreditAttribution: jsibley commentedHi. It looks like this was started at the end of 2011 and a possible solution has been mentioned almost a year ago.
Any chance of moving this forward?
Thanks.
Comment #32
Drupa1ish CreditAttribution: Drupa1ish commentedhttps://www.drupal.org/project/pathauto_entity works for me, started as a fork of Damien Tournoud's sandbox Pathauto integration for all Entity Types
Comment #33
clemens.tolboomIs this still needed now we have https://www.drupal.org/project/pathauto_entity ?
Comment #34
mvdve CreditAttribution: mvdve commentedI Think we can close this issue. I also use pathauto_entity and it works excellent.