Download & Extend

Problems with URL alias with pathauto and HS' [save-lineage-termpath] token

Project:Hierarchical Select
Version:6.x-3.x-dev
Component:Code - Taxonomy
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (duplicate)

Issue Summary

Here's a test I've run to find out if a user were to add a new term via the if the term would be added to the URL as defined by pathauto. In the test I have a parent term, and the user creates a new child term. The goal is to have the URL appear as parent/child/node-title

When using the following in pathauto [save-lineage-termpath-raw]/[title-raw] the node's URL becomes only /node-title, no terms are used within the URL.

When using [termpath-raw]/[title-raw] for the content type in pathauto, the URL becomes parent/node-title (the child term is not added to the URL. However, if I then edit the node and resave, the correct URL (parent/child/node-title) is created.

Is this something you're aware of? Have I missed something?

Dan

Comments

#1

Status:active» postponed (maintainer needs more info)

Can you still reproduce this problem?

#2

Status:postponed (maintainer needs more info)» closed (fixed)

Closing due to lack of response. Feel free to reopen.

#3

Status:closed (fixed)» active

Oh, I will reopen! I see this exact behavior. It is driving me batty. I just installed the latest (Aug 5th) dev and I still see this.

My path alias is set to [save-lineage-termpath-raw]/[title-raw] . When save, though, I get only "/node-title" rather than the parent/child/node-title I'm hoping for.

What other info do you need? I am running a bunch of other modules, though as far as I know none of them do anything with taxonomy or aliases.

EDIT: Also, if it's helpful, I checked in the db and the taxonomy hierarchy is listed correctly (3 is a parent of 14), and each node has entries for each item in lineage (node 58 has an entry for tid 3, and tid 14). So at least everything is getting saved correctly in there.

Thanks!

#4

Status:active» postponed (maintainer needs more info)

I will fix this, but only if you provide the login details to a demo site. Drupal login details + FTP/SSH access. Writing permissions for Hierarchical Select are sufficient (i.e. the rest may be read-only).

#5

Oh wouldn't you know it -- the demo site I have up doesn't have this issue (BAH!). I think I will be uploading the one I'm working on (that has the problem) within a couple of days -- when I do I will send you a message with login info. Thanks!

#6

Just saw the activity on this.

I do still have the issue, but it's on a live site. I've locked down the ability to add the associated content type so that I can fix the problems each time myself (we all know users will always go the simple route).

Looking forward to leenwebb's help in detailing the issue.

Dan

#7

Status:postponed (maintainer needs more info)» closed (fixed)

Closing due to lack of response. Feel free to reopen.

#8

Status:closed (fixed)» active

I finally managed to get up a site with this issue! Wim, I have sent you a message (via the d.o contact form) with login details. Thanks for all your patience and help!

#9

Title:Problems with URL alias with pathauto & HS for taxonomy» Problems with URL alias with pathauto and HS' [save-lineage-termpath] token
Priority:normal» minor
Status:active» postponed (maintainer needs more info)

Just a public follow-up: leenwebb has indeed given me access and I've looked at her site twice. The first time, Taxonomy form items didn't show up on the node form — something was wrong with her site. The second time (yesterday), I was able to reproduce the problem, but unable to test it properly because her setup wouldn't actually execute the changed code.

If somebody else has this problem: please create the minimum setup to reproduce this problem, do a DB dump, zip both the site and the DB dump and send it to me.

#10

Status:postponed (maintainer needs more info)» closed (fixed)

I just got a reply from leenwebb. She passed on the site to somebody else. Hence we won't be able to look into this further. Therefor, I'm closing this bug. Feel free to reopen if you have the same problem. When you do, act according to this:

Can you reproduce this on a vanilla Drupal site? If you cannot, keep on adding modules that you're using on your actual site until the problem is reproduced.

When you're able to reproduce this (on a vanilla Drupal site with the minimum number of modules to reproduce it), then please make a screencast of:

  1. your site configuration
  2. the problem being reproduced

That makes it easier for me to reproduce the problem. Thanks!

P.S.: don't have any screencast software yet? On Windows and Mac OS X, you can use the free Jing.

#11

Priority:minor» normal
Status:closed (fixed)» active

I reopened this issue because I've got the same "bug" and it is hard to discribe it without any visual references.

First the video: Screencast
You should download it, because in the browsers at screencast.com the video is overzoomed while playing

Now my description:

  • I've set up the vocab "produkte" in a hierarchical way.
  • I set pathauto to use the lineage of the vocab id "3" so it should looks like in the first node you can see in the screencast

The problem:

  • Only if I save my nodes using the drupal gui the url alias is saved correctly
  • If I try saving a node using "node_save($node)" the path looks like the path in the second node (screencast before I saved it)
  • The same if I use "node_submit($node)".
  • The same if I use both methods, loading the node and say "$node->pathauto_perform_alias = 1;" before saving.
  • So everything is saved correctly in the alias but not the lineage token

Do you understand?

Edit: My nodes wil all be created through an import script using node_save() I wrote myself. That's the reason why all nodes should have the right alias after creating it. There will be to much nodes to save them all manually.

Greetings

CKIDOW

#12

Status:active» closed (duplicate)

Marking this as a duplicate of #647688: HS' [save-lineage-termpath-raw] does not work — how to generate a "multi-level path addition" token?. tayzlor posted a patch that seems to fix it. Please test that patch and report back! :)

#13

Status:closed (duplicate)» active

Hello everyone.

Sorry for reopening this, but I'm having the same symptoms as the original post, and in looking at this in more detail, it looks like these are two separate issues. However, whether it's a bug with pathauto or hierarchical_select I'm not sure. I don't have a solution, but I've isolated the cause, so I hope the hints below help.

One way to make THIS particular bug (empty token values) appear is to delete a path alias and then use pathauto's "Bulk generate aliases for nodes that are not aliased" checkbox.

The line that seems to be at the root of the problem is line 555 (in my version) of hs_taxonomy.module below:

<?php
     
// Generate the per-vid "save-lineage-termpath" tokens.
     
foreach ($all_vids as $vid) {
       
$terms = array();
        if (
in_array($vid, $hs_vids)) {
         
$selection = $node->taxonomy[$vid]; // <- Hello... I'm line 555
         
$terms = _hs_taxonomy_token_termpath_for_vid($selection, $vid);
        }
?>

The problem is that the line above expects $node->taxonomy to be a two-dimensional array structured like taxonomy[vocabidofterm][termid] for all terms associated with that node. It does indeed arrive that way after saving a node at the edit form, but not always. Sometimes, it's a simple array of term id's, and sometimes it's an associative array of objects keyed by the term id. Why that is is beyond my understanding at the moment.

To illustrate, I've placed a dsm($object); at the top of that function, and dsm($values) at the bottom of that function. I've attached the outputs in various situations.

Thanks,
Al

AttachmentSize
badoutput-node-edit-form-before-save.jpg 75.85 KB
goodoutput-after-node-edit-form-save.jpg 58.86 KB
badoutput-pathauto-bulk-mode.jpg 83.95 KB

#14

Okay. What a piece of shit Node API is … something similar happens for Content Taxonomy, but apparently it also does for Taxonomy. Argh!

The patch to fix this is fairly simple of course. If you roll that patch, I'll review it and get it committed.

#15

Status:active» needs review

Hello again.

Wow, I thought "surely, we're doing this the hard way", but I looked at taxonomy's nodeapi, and it looks like it's written to handle all three cases too. What's worse is that the code there implies that the three structures can be mixed and matched on a given $node! I didn't probe further, but used taxonomy_node_get_terms just to be safe. Hopefully that's cached anyway in most cases.

By the way, the default "save-lineage-term-path" token still doesn't work, and there looks to be a bug here:

<?php
     
// We use the terms of the first vocabulary that uses Hierarchical
      // Select for the default "save-lineage-termpath" tokens.
     
$vids = array_intersect(array_keys($termsbyvocab), $hs_vids);
      if (!empty(
$vids)) {
       
$vid = $vids[0];
       
$values['save-lineage-termpath'] = implode($separator, array_map('check_plain', $terms)); // <-here
       
$values['save-lineage-termpath-raw'] = implode($separator, $terms); // <-here
     
}
?>

The fix is simple, but I'm on an older release, and it's a separate issue. Has that been fixed already?

Thanks,
Al Khaef

AttachmentSize
hs_taxonomy-420548-15.patch 1.25 KB

#16

Status:needs review» needs work

From what you cited, that looks like a bug indeed.

Now, your patch:
- thanks! :)
- it does not respect the Drupal coding standards (variable naming, spacing …)
- it uses taxonom_node_get_terms(), but that retrieves the *stored* terms, whereas this should use the terms in the $node object that was passed in, which may not yet have been saved! Correct me if I'm wrong though, I didn't look it up.

#17

Hi.

- You're welcome :) Thanks for a very useful module!
- Sorry about that. I'm pretty new to the community, as you may have guessed ;) ... I downloaded coder, and it doesn't complain. Please let me know if I missed anything.
- Arg. Good point. That's what I get for trying to keep it too clean :(. Also, it looks like pathauto has the same issue, because they're querying the database, rather than using the object passed in. Haven't tested it though.

Here's the updated patch. I tested it in all three scenarios again, this time also updating taxonomy on a new revision, and it picks up the new taxonomy.

Best regards,
Al

AttachmentSize
hs_taxonomy-420548-17.patch 1.49 KB

#18

Status:needs work» needs review

#19

Hello, I applied this patch and I'm getting warning messages on bulk update pathauto:
# warning: array_keys() [function.array-keys]: The first argument should be an array in [...]\sites\all\modules\hierarchical_select\modules\hs_taxonomy.module on line 573.
# warning: array_intersect() [function.array-intersect]: Argument #1 is not an array in [...]\sites\all\modules\hierarchical_select\modules\hs_taxonomy.module on line 573.

The line is this:
$vids = array_intersect(array_keys($terms_by_vocab), $hs_vids);

Anyway the bulk update is working fine except for this warnings

#20

Status:needs review» needs work

The patch still needs a little bit of work then :) Thanks for the report, p4trizio!

#21

Did someone manage to find final solution (without warnings...)?

#22

I have same problem.
I have a HS Select: country->province->city.
I want the nodepath like this xxx/country/province/city/node-title( or xxx/country-tid/province-tid/city-tid/node-title), but it doesnt work. following token give a empty value:
[save-lineage-termpath] (I you have enabled the "save lineage" setting of Hierarchical Select.)
[save-lineage-termpath-raw]
[save-lineage-termpath:vid]
[save-lineage-termpath-raw:vid]

I don't know why?

#23

I have this same problem with save-lineage-termpath-raw, in that using it (even after applying http://drupal.org/files/issues/hs_taxonomy_token.patch) produces nothing. i.e. [save-lineage-termpath-raw]/[title-raw] = /title-raw (only ... no lineage)

AND I have additional issues which are probably related in some way to the save-lineage-termpath-raw issue, as follows:

HS used to work with just [termpath-raw]/[title-raw], i.e. CORRECT:

Fun -> Current -> Party -> Jiminy Cricket
fun/current/party/jiminy-cricket

Now INCORRECT:

Fun -> Current -> Party -> Jiminy Cricket
business/fun/tech/fun/current/jiminy-cricket

Note: The 3 "parent/primary" taxonomy terms are "Business", "Tech" and "Fun". Each has several "children", and each of those children also has children. I need (and used to have) "parent/child/grandchild/title"

Using the current module(s), the HS URL generated first includes *all* of the parent terms (business/fun/tech/) then includes the "real" parent (fun/) then its first child (current/) and finally the title-raw (jiminy-cricket) ... without ever using the selected "grandchild" (party/)

So I end up with: parent1/parent2/parent3/parent/child/title (all parents + no grandchild)

Swapping out [save-lineage-termpath-raw]/[title-raw] instead of [termpath-raw]/[title-raw] gives me just the title ... no termpath. (I applied the http://drupal.org/files/issues/hs_taxonomy_token.patch patch and cleared my caches several times with no change.)

I have not updated the Hierarchical Select module in between these behaviors. Here is some module info:

Drupal core 6.x-dev (2010-Sep-06)(6.19)
Hierarchical Select 6.x-3.x-dev (2010-Oct-08)

Modules that have been updates since Hierarchical Select was working correctly:

Chaos tool suite 6.x-1.x-dev (2010-Oct-29)
Panels 6.x-3.x-dev (2010-Oct-29)
Pathauto 6.x-2.x-dev (2010-Oct-26)
Wysiwyg 6.x-2.x-dev (2010-Oct-18)

(Today I updated from Pathauto 6.x-2.0-alpha3, installed prior to HS, to the newer dev version without any change in this issue. I do not believe Pathauto is messing with it, as it was installed before HS and HS was working fine with it. HS is my original installation of that module plus the patch noted, above.)

Frustrating in that it used to work, but now it's broken.

[UPDATE: The module is grabbing ALL of the parents from the bottom up (tested with a much larger vocabulary), *and* "tags" are behaving correctly, so it's not a global issue ... just with HS.]

#24

Now I'm back looking at Pathauto, after going through Token ... in particular: pathauto/pathauto.tokens.inc

function _pathauto_token_values($type, $object = NULL, $options = array(), $label = NULL) {
      // Tokens [termpath], [termpath-raw], and [termalias].
      if (module_exists('taxonomy')) {
        // Get the lowest-weighted term from the lowest-weighted vocabulary.
        // This query is copied from @taxonomy_node_get_terms()
        $term = db_fetch_object(db_query_range('SELECT t.* FROM {term_node} r INNER JOIN {term_data} t ON r.tid = t.tid INNER JOIN {vocabulary} v ON t.vid = v.vid WHERE r.vid = %d ORDER BY v.weight, t.weight, t.name', $object->vid, 0, 1));
        if ($term) {
          $values = array_merge($values, _pathauto_token_values('taxonomy', $term, $options, 'term'));
          ...

======================
print_r($values)
Array (
[termpath] => Array (
  [0] => Parent Z
  [1] => Parent Y
  [2] => Parent X
  [3] => Child )
[termpath-raw] => Array (
  [0] => Parent Z
  [1] => Parent Y
  [2] => Parent X
  [3] => Child )
[termalias] => select/parent-x/child
[termalias-raw] => select/parent-x/child
)
======================

Note the descending alphabetical order of the Parents in the $values array. That's how they display in the alias:

parent-z/parent-y/parent-x/child/title

It seems the query (which IS exactly like the one in taxonomy_node_get_terms, albeit in a different implementation) is pulling ALL of the parents (as seen in my earlier post) and the selected child (which is the correct child), but it is not pulling the "grandchild" at all.

Note that termalias and termalias-raw are almost correct ... but are also missing the grandchild.

In my earlier post I wrote that the alias ended up like:

business/fun/tech/fun/current/jiminy-cricket

In fact, they are in descending alphabetical order, not like I wrote when I made up a few terms for this post. ;) I'll correct the order, now.

Notice how the alias uses: parent-z/parent-y/parent-x ... and then reiterates parent-y, which was the selected parent. When I select the first parent, alphabetically (parent-x,) it is NOT reiterated, i.e. if I had selected 'business' as the parent, with this issue the alias would be expected to be:

tech/fun/business/business/current/jiminy-cricket

but, instead, it just drops the parent and ends up as:

tech/fun/business/current/jiminy-cricket

I can't tell if this is an artifact of an "awareness" of the selected parent or what. I'm still working my way through all of the various modules that contribute to creating an alias. This is just an update, really. Still no joy. Onward.

#25

I abandoned working with Pathauto and went back to HS and ... Okay. Here's my extremely hackie "fix", IN NO WAY is this ready for a patch, but this is where I found the problem and what I did to get my own site working as it did, before:

The problem I found was in hierarchical_select/modules/hs_taxonomy.module, in the hs_taxonomy_token_values function. In the code I will paste, below, in the foreach loop that begins at line 660, the CORRECT aliased path is captured as an element of the $values array.

THE PROBLEM seems to me to be that because the $terms array is reset with each iteration, by the time the loop ends, $terms is empty ... which is very bad for its use at line 678! You can't implode an empty array!

My sloppy fix is two-fold:

(1) Instead of using the same implode() function at line 678, I simply assign the $values element to whatever the value of the VID-SPECIFIC $values element was, from the foreach loop. Because the temporary $vids variable at line 677 holds only the first element of the $vids array, populated at line 674 with the correct $vid (at least in my case), referring to the appropriate element of the $values array works consistently.

(2) Unfortunately, something wicked happens to the $values['save-lineage-termpath-raw'] value somewhere down the line, and it does NOT get translated to the proper format for the URL alias, so, in lines 685, 686 and 687, I rolled my own clean-up sequence, and ... voila ... I end up with the "correct" path alias.

Nasty, dirty and kludgy ... but maybe smarter heads than mine will be able to work something out that's more in keeping with the Drupal style guide and whatnot. I really need to move on to other issues ...

Here's the code (the "jb" in "jbpath" is me) ... which already includes the patch from http://drupal.org/files/issues/hs_taxonomy-420548-17.patch

Thanks for this module, Wim. Sorry about messing up your living room ... ;)

=================================================
606 function hs_taxonomy_token_values($type, $object = NULL, $options = array()) {
607   static $hs_vids;
608   static $all_vids;
609
610   $separator = variable_get('hs_taxonomy_separator', variable_get('pathauto_separator', '-'));
611
612   $values = array();
613   switch ($type) {
614     case 'node':
615       $node = $object;
616
617       // Default values.
618       $values['save-lineage-termpath'] = $values['save-lineage-termpath-raw'] = FALSE;
619
620       // If $node->taxonomy doesn't exist, these tokens cannot be created!
621       if (!is_object($node) || !isset($node->taxonomy) || !is_array($node->taxonomy)) {
622         return $values;
623       }
624
625       // Find out which vocabularies are using Hierarchical Select.
626       if (!isset($hs_vids)) {
627         $hs_vids = array();
628         $result = db_query("SELECT SUBSTRING(name, 30, 3) AS vid FROM {variable} WHERE name LIKE 'taxonomy_hierarchical_select_%' AND value LIKE 'i:1\;';");
629         while ($o = db_fetch_object($result)) {
630           $hs_vids[] = $o->vid;
631         }
632       }
633
634       // Get a list of all existent vids, so we can generate an empty token
635       // when a token is requested for a vocabulary that's not associated with
636       // the current content type.
637       if (!isset($all_vids)) {
638         $all_vids = array();
639         $result = db_query("SELECT vid FROM {vocabulary}");
640         while ($row = db_fetch_object($result)) {
641           $all_vids[] = $row->vid;
642         }
643       }
644
645       // Build consistency to handle all three forms of $node->taxonomy
646       foreach ($node->taxonomy as $key => $item) {
647         if (is_object($item)) {
648           $terms_by_vocab[$item->vid][] = $item->tid;
649         }
650         else if (is_array($item)) {
651           $terms_by_vocab[$key] = $item;
652         }
653         else if ($item) {
654           $term = taxonomy_get_term($item);
655           $terms_by_vocab[$term->vid][] = $term->tid;
656         }
657       }
658
659       // Generate the per-vid "save-lineage-termpath" tokens.
660       foreach ($all_vids as $vid) {
661         $terms = array();
662         if (in_array($vid, $hs_vids) && isset($node->taxonomy[$vid])) {
663           $selection = $terms_by_vocab[$vid];
664           $terms = _hs_taxonomy_token_termpath_for_vid($selection, $vid);
665         }
666
667         $values["save-lineage-termpath:$vid"] = implode($separator, array_map('check_plain', $terms));
668         $values["save-lineage-termpath-raw:$vid"] = implode($separator, $terms);
669
670       }
671
672       // We use the terms of the first vocabulary that uses Hierarchical
673       // Select for the default "save-lineage-termpath" tokens.
674       $vids = array_intersect(array_keys($terms_by_vocab), $hs_vids);
675
676       if (!empty($vids)) {
677         $vid = $vids[0];
678 #        $values['save-lineage-termpath'] = implode($separator, array_map('check_plain', $terms));
679 #        $values['save-lineage-termpath-raw'] = implode($separator, $terms);
680         $values['save-lineage-termpath'] = $values["save-lineage-termpath:$vid"];
681         $values['save-lineage-termpath-raw'] = $values["save-lineage-termpath-raw:$vid"];
682
683       }
684
685       $jbpath1 = str_replace("-","/",$values['save-lineage-termpath-raw']);
686       $jbpath2 = str_replace(" ","-",$jbpath1);
687       $values['save-lineage-termpath-raw'] = strtolower($jbpath2);
688
689       break;
690   }
691
692   return $values;
693 }
====================================================

#26

the patch jb has in #25 works for me as well. before the termpath-raw was always blank.

Array
(
    [save-lineage-termpath-raw] =>
    [save-lineage-termpath] =>
    [save-lineage-termpath:1] =>
    [save-lineage-termpath-raw:1] =>
    [save-lineage-termpath:3] =>
    [save-lineage-termpath-raw:3] =>
    [save-lineage-termpath:6] => Dog/Labradoodle
    [save-lineage-termpath-raw:6] => Dog/Labradoodle
    [save-lineage-termpath:7] =>
    [save-lineage-termpath-raw:7] =>
    [save-lineage-termpath:14] =>
    [save-lineage-termpath-raw:14] =>
    [save-lineage-termpath:19] =>
    [save-lineage-termpath-raw:19] =>
    [save-lineage-termpath:20] =>
    [save-lineage-termpath-raw:20] =>
)

so thank you very much for the work-around!

sm sep issue: i was also never able to get the [save-lineage-termpath-raw:vid] to take in the path-auto automated alias settings screen. If I had [save-lineage-termpath-raw:vid], it would take but that is exactly what was in the path. If I put [save-lineage-termpath-raw:6], it would fail the form validation (invalid token).

#27

Status:needs work» needs review

The solution from #25 works fine for me when $node->taxonomy follows the structure array(tid => term, ...), but not for array(vid => array(tid => term, ...), ...). I made some modifications and now it works for me.

I also changed the lines which should set the general token (without vid) to the correct value. This failed because it was using $terms, which is used in the loop before.

When I used "[save-lineage-termpath-raw]/[title-raw]" in pathauto, the result was that I got aliases like:

/First Category-Second Category/node-title

But the desired effect is:

/first-category/second-category/node-title

That's impossible by now. Categories are imploded by the separator that is used in pathauto to separate words. Hence I added a token called [save-lineage-termpath-alias-raw] which implodes on slashes and simplify each category name with pathauto_cleanstring(). With this token I'm able to get the desired aliases in pathauto. This token is only available when pathauto is enabled.

I have 2 patches attached:
hierarchical_select_420548.patch: Fixes $node->taxonomy structure problem
hierarchical_select_420548_alias.patch: Identical, but with alias token

AttachmentSize
hierarchical_select_420548.patch 1.99 KB
hierarchical_select_420548_alias.patch 4.23 KB

#28

subscribing

#29

subscribing..

#30

Status:needs review» closed (duplicate)

Duplicate of #931902: Update Token integration to support recent versions of Token. If the fixes committed for #931902: Update Token integration to support recent versions of Token don't fix all problems in this issue, please create a new issue, because at least *most* problems have been fixed by that.

#31

OK... new issue in #1073858: [save-lineage-termpath] token generation revisited

Set to 'needs review', but should be trivial to set RTBC by the people who actually contributed the fix in #25 / #27.
[ I took the patch in #27 and fixed an isset() on one line.
Ignored the 'termpath-alias' tokens, since that is a separate issue - and it's not impossible to get the right tokens by now. You can set $conf['hs_taxonomy_separator'] = '/'; in your site's settings.php. ]

Edit:
and Wim has made it clear in the related issue, that he is not looking at the code himself.

And I can understand if he's completely busy.
But the only reason that this is not set RTBC yet, is that Wim (after setting this issue to duplicate when it really wasn't - twice) told people to open a new issue. Thereby working against this reaching RTBC state.

So please review, people.

nobody click here