Hi, I'm a beginner. I've just installed Drupal 7 with XAMPP on Windows XP. I've created a vocabulary (myvocabulary) with many nested terms. With Pathauto I would like to create urls such as www.example.com/parent_term/child_term.

In "Configuration » Search and metadata » URL aliases" I've set "Pattern for all myvocabulary paths" to [term:parent]/[term:name].

I've enabled also "Bulk generate aliases for terms that are not aliased".

Here is what happen when I hit the button "Save configuration":

1. All existing terms which do not already have aliases get a new correct url www.example.com/parent_term/child_term

2. When I create a new child term in the vocabulary, it get the wrong url www.example.com/child_term (In other words Drupal can't fetch the parent term for new child terms)

Is it a bug?

Note: sometimes when I apply a new URL Pattern in "Configuration » Search and metadata » URL aliases" with the option "Bulk generate aliases for terms that are not aliased" active, I get the following message:

The configuration options have been saved.
Bulk generation of terms completed, 23 aliases generated

Notice: Trying to get property of non-object in taxonomy_tokens() (line 141 of C:\xampp\htdocs\example\modules\taxonomy\taxonomy.tokens.inc).

(This last error message is repeated many times)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

Title: Pathauto for taxonomy term paths » Taxonomy parents need to be saved before term hooks are called
Project: Pathauto » Drupal core
Version: 7.x-1.x-dev » 7.x-dev
Component: Code » taxonomy.module
Assigned: Unassigned » Dave Reid

This is a pretty major core bug. Posting a patch shortly.

Dave Reid’s picture

Status: Active » Needs review
FileSize
5.52 KB

So several issues here:
1. Term parents are not saved prior to the hook_taxonomy_term_insert/update being executed. This was exposed in pathauto which tries to get the parent term's tokens and there is no hierarchy there. These kinds of hooks should always be post all insert or update operations.
2. When using [term:parent:*] tokens with a term that does not have any parents, this causes a PHP notice because taxonomy_get_parents() returns an empty array. This was also exposed in pathauto and the tests have been added to fix this bug.

Status: Needs review » Needs work

The last submitted patch, 844410-taxonomy-hook-token-D7.patch, failed testing.

Dave Reid’s picture

Status: Needs work » Needs review
FileSize
5.06 KB

Re-rolled to not use $term->is_new which affects processing if the value stays in the term object.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

Code looks proper and bot is happy. More test coverage as well.

marcingy’s picture

Priority: Normal » Major

Changing to major as per tag.

MustangGB’s picture

Tag update

Dave Reid’s picture

Issue tags: +token

Adding the token tag since this affects token functionality when using [term:parent] tokens.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Looks good. Committed to CVS HEAD.

Dave Reid’s picture

Status: Fixed » Reviewed & tested by the community

Haven't actually seen this committed on http://drupal.org/project/cvs/3060 yet? :/

Dries’s picture

Status: Reviewed & tested by the community » Fixed

For real now. Committed to CVS HEAD.

Dave Reid’s picture

Excellent! Thank you Dries, that fixes two hacks in Pathauto for D7.

Status: Fixed » Closed (fixed)
Issue tags: -token

Automatically closed -- issue fixed for 2 weeks with no activity.