Was working with organic groups, wanted to alias based on multiple taxonomies as well as multiple organic groups, since the template used for display depends on the OG.

The following patches pathauto_create_alias to deal with $placeholders when an entry may be an array. Then wrote my <custom>_pathauto_node to return an array of values instead of a single value for each placeholder for [cats] and [ognames].

CommentFileSizeAuthor
pathauto_multipleplaceholders.patch1.29 KBmikegull

Comments

greggles’s picture

Version: 6.x-1.x-dev » 5.x-2.x-dev

This is an interesting idea, but I'm not sure how I feel about it as a feature.

I can see the goal, but it seems like it would be pretty impractical for most group names and numbers of groups.

E.g.this post about paths and internationalization would get an alias something like:

g.d.o/internationalization/paths/pathauto-i18n-integration

That seems a bit rough to me.

I'm also a little concerned about recursive functions in general when users often have catpath pattern with multiple deeply nested taxonomies. Yikes.

I'd love to get more input from other folks on this patch (whether they like the concept or not) prior to applying it.

Thanks very much, mikegull, for the idea and the patch!

mikegull’s picture

Greggles-

Please re-read the patch. I'm not concatenating....
The patch allows a node to have multiple aliases for each combination.
Your post would get two aliases:
g.d.o/paths/pathauto-i18n-integration
g.d.o/internationalization/pathauto-i18n-integration

I.e., if I return [cats] => array( 'blue', 'red', 'green') and my path is '[cats]/[nid]', then I would get three aliases:
blue/3
red/3
green/3

Likewise, if I had two arrays, i.e., [ognames] => array('circle', 'square') and my pattern was '[ognames]/[cats]/[nid]', I would end up with 6 aliases:
circle/blue/3
circle/red/3
circle/green/3
square/blue/3
square/red/3
square/green/3

This enables me to alter CSS classes in the template based on q[0] and q[1], customizing by the og or category that an item is being pulled up in.

I think this functionality would be useful for other people. I deliberately did NOT patch the placeholders for [cat] or [catpath], but implemented _pathauto_node with my own placeholders, for [cats] and [ognames], so as not to cause other side effects.

greggles’s picture

Yes, I see. I was definitely confused at first.

I'm still not enthusiastic about this patch, though :/

And I'm afraid I still don't entirely understand. You mentioned that you implemented your own _pathauto_node, right? So, basically your patch doesn't do anything on it's own, but with additional code (that you're keeping out of this, and that's OK) it would handle the multiple aliases. Is that right?

It would be very helpful for me in testing to have that additional code so that I don't have to write it.

The idea strikes me as potentially "bad" in certain situations because the content is duplicated at multiple URLs which is seen as a usability problem and an SEO problem. On the other hand, I do see the potential benefits of this, so I'd be willing to put this in. Again, I'd also love to get a second or third opinion on this. Perhaps you could get some discussion going at http://groups.drupal.org/paths ?

mikegull’s picture

Title: Allow pathauto to deal with multiple placeholders » Sample code

Sure thing, sample code as follows:

function mymodule_pathauto_node($op, $node=NULL) {
  static $groups;  //cache our list of groups in between calls for speed
  switch ($op) {
    case 'placeholders':
      $placeholders = array();
      $placeholders[t('[ognames]')] = t('The field_shortnames of the organic groups this post belongs to.');
      return $placeholders;
    case 'values':
      if (!isset($groups)) {
        $sql = 'select nid, field_shortname_value from content_type_group';
        $result = db_query($sql);
        while ($record = db_fetch_array($result)) {
          $groups[$record['nid']] = $record['field_shortname_value'];
        }
      }
      $results = array();
      if ($node->og_groups) {
        foreach ($node->og_groups as $gid) {
            if ($gid != 0) {
              $name[] = pathauto_cleanstring($groups[$gid]);
            }
        }
      }
      $results[t('[ognames]')] = $name;
      return $results;
    default:
      break;
  }
}

I've done something similar with [cats].

Our path is "[ognames]/[title]" for the purposes of this example.

So, in the head of page.tpl.php template, we then have:

<?php
$myq = split('/',$_REQUEST['q']);
$og = $myq[0];
?>
<style type="text/css" media="all">@import ""<?php print base_path() . path_to_theme() ?>/style.css";</style>
<style type="text/css" media="all">@import ""<?php print base_path() . path_to_theme() ?>/style-<?php print $og;?>.css";</style>

Ideally, we should filter $og to make sure it's valid and style-{$og} exists, but that would be another function call to get the group field_short_name values.

Voila! Based on the OG in the URL alias, I'm presented with a completely different look and feel for the exact same content.

So... if you'd like to move this over to the discussion at Groups, please do, I'll gladly join in there.
If there's another better way to do what I'm trying to accomplish, I would gladly try it out.

Also, the other big issue with this approach is the removal of aliases, but I think that's a bigger issue.

greggles’s picture

Title: Sample code » if multiple placeholders exist create multiple aliases for a node

Note that issues are not like comments, so changing the title will change it for the whole issue. I changed it to something that seemed more descriptive.

And thanks for the code.

hyuugurt’s picture

I'm curious if there is an updated version of this patch as I can't seem to patch the latest stable version with it. I'd really like this functionality if it's possible.

Freso’s picture

I think the idea behind this is sound. If people don't want their content to appear in multiple places, they'll either have to not allow content (terms, nodes, ...) to have multiple parents or simply avoid using the catpath/termpath tokens for that vocabulary - as was said in #241608: Duplication of ancestor terms in catpath/termpath when term has multiple parents.

exaboy’s picture

ive tried the above code on my installation of drupal 5.3 and im not getting the result at all.

It seems as though i might be missing some code. could you include your whole module?

Is there anyone else that has got this to work?

MiMe’s picture

There should Never be more than One alias (URL) for a node at any give time. Read all about duplicate content, or at the Official Google Webmaster Central Blog.

dave reid’s picture

Status: Needs review » Closed (won't fix)

At this point, this issue is going to be marked as won't fix. This is either not in the direction of the project, or too out of the project scope.

This message is automatically generated. If you feel it could be improved, feel free to comment on http://drupal.org/node/467548

Note: Agreed. This is not a very good idea. If anything it should be accomplished as a separate contrib module, but Pathauto should encourage the use of 1 alias per path.