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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

Status: Active » Postponed

Yes 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

Dave Reid’s picture

Damien Tournoud’s picture

Also see http://drupal.org/sandbox/damz/1332096 for a quick-and-dirty workaround.

Dave Reid’s picture

Title: Pathouto should work with all entity types » Pathauto should work with all entity types
Jax’s picture

It 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:

  • node is nothing more than mapping the internal url node/% to the alias and knowing that the % is a node id
  • user maps user/%
  • term maps taxonomy/term/%

It could be replaced by a more generic form where one could:

  • Define the internal URL to be mapped
  • What entity type the ID is for
  • Optionally which bundle for that entity type
  • Define the alias with tokens

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

Dave Reid’s picture

Yes, 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.

Ale.bcn’s picture

subscribing :)

klausi’s picture

Stop subscribing, start following: http://drupal.org/node/1306444

Jax’s picture

FileSize
23.56 KB

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

Jax’s picture

FileSize
23.49 KB

The previous mock-up is missing a text field...

Ale.bcn’s picture

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

:(

klausi’s picture

Ale.bcn’s picture

Hi Klausi,

hehehe thanks!

aufumy’s picture

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

kevinquillen’s picture

Jax’s picture

Just FYI, I've implemented the module for which I made a mock up since we needed it:
http://drupal.org/sandbox/jax/1572908

Oceanman’s picture

Jax, 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?

Jax’s picture

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

Syd Barrett’s picture

Hi guys,

has anyone used Damien's or Jax's code? What's your feedback?

kevinquillen’s picture

Pathauto Entity has worked fine for me other than #15.

Anonymous’s picture

Since Entities were presented in D7 this should be at least a "major" priority.

Barto.G’s picture

Well 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

Jax’s picture

@guizmo: The router item should be something like taxonomy/% or my-view/%

Barto.G’s picture

@jax thanks,
Works perfectly !

Anonymous’s picture

Any development yet?

kevinquillen’s picture

I am still using #3 and #15 to achieve this.

Anonymous’s picture

I 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

acbramley’s picture

FileSize
4.19 KB

It'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:

/**
 * Implements hook_entity_insert().
 */
function my_entity_entity_insert($entity, $type) {
  if ($type != 'my_entity') {
    return;
  }
  module_load_include('inc', 'my_entity', 'my_entity.pathauto');
  my_entity_update_alias($entity, 'insert');
}

/**
 * Implements hook_entity_update().
 */
function my_entity_entity_update($entity, $type) {
  if ($type != 'my_entity') {
    return;
  }
  module_load_include('inc', 'my_entity', 'my_entity.pathauto');
  my_entity_update_alias($entity, 'update');
}

/**
 * Implements hook_entity_delete().
 */
function my_entity_entity_delete($entity, $type) {
  if ($type != 'my_entity') {
    return;
  }
  pathauto_entity_path_delete_all('my_entity', $entity, "my_entity/{$entity->pid}");
}

Hope this helps someone :)
Note: I now see that this is what the sandbox does but more generically, nice!

solquimpo’s picture

Hi 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:

core = 7.x
api = 2

; Pathauto Entity (sandbox project)
projects[pathauto_entity][type] = module
projects[pathauto_entity][subdir] = contrib
projects[pathauto_entity][download][type] = git
projects[pathauto_entity][download][url]=http://git.drupal.org/sandbox/damz/1332096.git
projects[pathauto_entity][download][branch]=7.x-1.x
; Add bundle support, generic bulk update and url path settings on entity add/edit form
; https://drupal.org/node/1947226
projects[pathauto_entity][patch][] = http://drupal.org/files/1947226-7199810-converted-zipped-files-to-patch.patch

Thanks to all who worked/are working on this module. It is very useful. :)

acbramley’s picture

+1 to get this promoted to a full project, then maybe merge in at a later date?

jsibley’s picture

Issue summary: View changes

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

Drupa1ish’s picture

https://www.drupal.org/project/pathauto_entity works for me, started as a fork of Damien Tournoud's sandbox Pathauto integration for all Entity Types

clemens.tolboom’s picture

Issue summary: View changes

Is this still needed now we have https://www.drupal.org/project/pathauto_entity ?

mvdve’s picture

Status: Postponed » Closed (won't fix)

I Think we can close this issue. I also use pathauto_entity and it works excellent.