It doesn't seem that a URL is generated with the taxonomy category for a free tagged node. Is this by design or is this a bug? The order of execution of hook_invoke may have something to do with as taxonomy comes after path. Perhaps renaming the module may be a solution?

CommentFileSizeAuthor
#11 pathauto_node.inc_8.patch420 bytescre8d

Comments

greggles’s picture

Marked http://drupal.org/node/46682 as a duplicate of this. Note that bulkupdate will fix this issue.

cre8d’s picture

Hi -

Here's the details for my setup:

Drupal 4.7.3
pathauto.module,v 1.22.2.8 2006/10/11 22:35:18

pathauto settings:

Haven't touched anything under Geneder
Node path settings:
Default path pattern: [cat]/[title]
Pattern for blog entry paths: (empty)

Blog settings:

Free tagging vocabulary + list selection vocabulary

Create a blog entry free tagged "category" called "blog title" and it comes up with

/blog-title

Bulk updating paths it changes to:

/category/blog-title

cre8d’s picture

I'm quite keen to help fix this bug because it's really a problem on my site having to run bulk update all the time (which is getting slower as the site grows). Can anyone give me any pointers on where to start looking?

greggles’s picture

Sure - take a look in pathauto_taxonomy.inc and compare the normal path with the bulkupdate path.

That should lead you to the issue (since bulk updates fix the problem).

cre8d’s picture

Category: support » bug

I've been trying to track down the problem and have discovered that $placeholders is not set correctly.

cat, catalias, are empty:

Array ( [[title]] => End-of-year-surprise [[yyyy]] => 2006 [[mm]] => 10 [[mon]] => Oct [[dd]] => 21 [[day]] => Sat [[hour]] => 18 [[min]] => 23 [[sec]] => 52 [[week]] => 42 [[nid]] => 427 [[type]] => blog-entry [[user]] => Rachel [[book]] => [[bookpath]] => [[cat]] => [[vocab]] => [[catalias]] => [[catpath]] => / [[menu]] => [[menupath]] => )

On bulk update, $placeholders is set correctly, hence the reason why that works and not creation.

Am now looking through pathauto_node.inc to find out where $placeholders is going wrong.

cre8d’s picture

Oops just saw your post - thank you. Will keep hunting.

cre8d’s picture

More info for others having the same issue, from pathauto_node.inc. This is where it's going wrong:

  // And now taxonomy, which is a bit more work
  
  if (module_exist('taxonomy') && is_array($node->taxonomy)) {
    // When editing a node, the taxonomy array might have one or more zero
    // term IDs. Ignore them...
	
    foreach ($node->taxonomy as $firsttermid) {
      if ($firsttermid) {
        break;
      }
    }

My $node->taxonomy looks like this:

// [taxonomy] => Array ( [tags] => Array ( [1] => My category ) [2] => 5 )

I guess the taxnomoy structure changes if using free vocab (i.e. tagging).

So $firsttermid is broken.

Also, interestingly [taxonomy] doesn't include the tag's ID ([2] => 5 is another vocabulary and not the ID of "My category").

cre8d’s picture

And the reason it works for bulk update, this code is in there:

   if (module_exist('taxonomy')) {
      // Must populate the terms for the node here for the category
      // placeholders to work
      $node->taxonomy = array_keys(taxonomy_node_get_terms($node->nid));
    }

But putting this code in on alias creation $node->taxonomy returns as an empty array. I'm guessing this is because the node isn't yet officially in the database, it's still being created?

cre8d’s picture

Ok, I think I have fixed this - any suggestions/improvements please let me know:


 // And now taxonomy, which is a bit more work
  
  if (module_exist('taxonomy') && is_array($node->taxonomy)) {
    // When editing a node, the taxonomy array might have one or more zero
    // term IDs. Ignore them...
		
    foreach ($node->taxonomy as $firsttermid) {
      if ($firsttermid) {
        break;
      }
    }
	
    $term = taxonomy_get_term($firsttermid);
	
	   if (!$term->name){
			$terms = $node->taxonomy;
			$tags = $terms['tags'];
			$term->name = $tags[1];
	}
	
    $placeholders[t('[cat]')] = pathauto_cleanstring($term->name);

I.e. I have added in these lines to pathauto_node.inc:

	   if (!$term->name){
			$terms = $node->taxonomy;
			$tags = $terms['tags'];
			$term->name = $tags[1];
	}
greggles’s picture

Hello @cre8d - great work finding the source of the issue.

Can you please provide your change as a patch?

Check http://drupal.org/diffandpatch for details on how to create this.

cre8d’s picture

StatusFileSize
new420 bytes

Thanks - sorry I rambled so much!

I have applied for a CVS account so apologies if patches can only be submitted with CVS accounts. I haven't submitted patches before :)

omizus’s picture

Hi there

In my case I still had problems with multiple tags and [vocab], so I've modified your code a bit and I got this:

<?php
	if (!$term->name) {
		$terms = $node->taxonomy;
		$tags = $terms['tags'];
		foreach($tags as $vocab_id => $tag_list) {
			$term->vid = $vocab_id;
			$term->name = preg_replace('/\s*\,.*/', '', $tag_list);  // in case there are multiple tags submitted
			if ($term->name) { // we skipped all vocabs with no tags for this node
				break;
			}
		}
	}
?>

I'm a copy&paste programmer, so the code might be faulty. Seems to be working in my case though.

greggles’s picture

Can you guys confirm that this still isn't working with the latest code?

I just tried in both 4.7 and HEAD and it seems to be working fine.

MikeyGYSE’s picture

Confirming that Ozzimus' code DOES work and only uses the top level category,

E.g. Page with; tags: Legal, licenses, GPL, GNU; and title: Licenses: General Public

generates the path:

/legal/licenses_general_public

:-)

Now if I could just make it stop sorting my tags alphabetically *rolls eyes*

greggles’s picture

@MikeyGYSE - can you confirm which version of pathauto_node.inc you were using when it didn't work for you?

MikeyGYSE’s picture

// $Id: pathauto_node.inc,v 1.17.2.6 2006/10/13 14:51:30 greggles Exp $ <-- doesn't work without the modifications submitted by omizus

greggles’s picture

Version: 6.x-1.x-dev » 4.7.x-1.x-dev

Then I think this problem is a 4.7 problem and not a HEAD one. When I get time I will investigate it under 4.7 and see if the changes mentioned work as advertised.

@cre8d or @omizus or @MykeyGYSE- could one of you you please create a patch of the changes that follows the Drupal standard: http://drupal.org/diffandpatch

It makes it easier for me to understand where you have found the problem and how to fix it. Thanks.

firstov’s picture

I just updated pathauto on my site and I'm still not able to make categories with free-tagging work correctly.
version of pathauto:
//$Id: pathauto_node.inc,v 1.17.2.6 2006/10/13 14:51:30
Drupal version: 4.7.4

Settings of my blog type node:
blog/[user]/[vocab]/[catpath]/[title]

when vocab="topic" and term="whatever" it should create /blog/user/topic/whatever/some_article_title and what it does instead,
it creates /blog/user/some_article_title URL (missing "/topic/whatever" part)

After I've applied path it now creates /blog/user/topic/some_article_title URL (missing "whatever" term!)
So the path still needs to be adjusted to include the term.
Thanks

greggles’s picture

@firstov - thanks for confirming this. I've found this problem (it causes an error to be printed to the screen in Drupal5) and will be looking into a solution shortly (i.e. the next couple of days).

greggles’s picture

Status: Active » Closed (duplicate)

See http://drupal.org/node/92900.

Cre8d and omizus your tips really helped me in creating the patch on that issue. To fix that error (which is pretty critical) I basically also have to fix this whole freetagging/category problem so I am closing this issue as a duplicate in favor of that one. I would appreciate all of your assistance in testing/reviewing that patch.

@MikeyGYSE - I'm now understanding your point about alphabetic sorting and there is also a problem if you have a low weight freetagging vocabulary with no terms in it, a heavy freetagging vocabulary that does have values, and other "normal" vocabularies in between that have values because pathauto will use the heavy freetagging terms first. I see that as a low priority corner case that's tough to solve in Pathauto now, so I'm holding off on it. I'd like to change around the Taxonomy structure a little to make that easier, but I'm rambling and those are problems for a different day in a different issue queue ;)