[menupath-raw] issue for unpublished nodes

mshaver - November 26, 2008 - 01:35
Project:Token
Version:6.x-1.12
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Description

It looks like the menupath token is problematic with pathauto in the following situations:

- node created with menu item added, but node left unpublished

What this does is alias the node to the parent menu item, causing a duplicate alias or rather an alias of the parent item with a -0 after it. I can't then even get to the original alias without the -0. Has anyone else see this?

#1

benorgan - July 21, 2009 - 13:10

I'm experiencing this too, does anyone have a fix?

#2

benorgan - July 21, 2009 - 16:15
Version:6.x-1.11» 6.x-1.12
Priority:normal» critical

Changed version, also tested with dev version and same behaviour

#3

greggles - July 21, 2009 - 16:36

Marked #526222: When creating an unpublished node and using menupath as the alias the alias is incorrect as a duplicate.

@benorgan - do you plan to work on this? Marking it as critical doesn't actually help to get the bug fixed sooner.

#4

benorgan - July 21, 2009 - 16:54
Priority:critical» normal

This is indeed a duplicate of that comment.

I do have some time to work on this but I don't really know how to go about it.

I understand it's something to do with using the menu_tree_all_data function from includes/menu.inc which then calls menu_tree_check_access but this function limits it's query to nodes with status = 1 (i.e. published). So I guess there needs to be another way to get the menu information for the token, but I don't know Drupal well enough to know where to look.

Was marked as critical as I really need this for a site that's going into production.

#5

mikshimonster - July 26, 2009 - 04:02

#529284: use path module to render url

I'm having the same issue here. I wasn't sure which module was responsible for this. I dont have any programming skills either...

If your intention is to create multiple pages in unpublished/pending mode for a reviewer/editor, it would be nice to see the followings when creating each page (btw, im building a marketing site and not a community):

  1. creates unpublished/pending menu item (in menu) that can only be viewed by certain users (reviewers/editors) who can view unpublished contents. this menu item must also be visible in Parent Item when creating another page so you can attach a child page to it.
  2. pathauto creates the correct menupath for the unpublished/pending revision.
  3. when published, both menu item and page become available to public.

something like this, acting as staging server. i guess its easier to say than something done :)

#6

alexharries - August 4, 2009 - 07:05

One possible solution would be to present a version of [menu-trail-parents-raw] with slashes between the parents (at the moment this token has no slashes), and then use:

[menu-trail-parents-raw]/[title-raw] (or, even better, present [menu-trail-parents-raw] with a trailing slash if and only if it is longer than 0)

... instead of:

[menupath-raw]

It looks like this might give a virtually identical result, and will ensure there's a sensible title. Example URLs might then be:

Location on menu: foo/bar/turkey/mango/noodle
[menupath-raw] = foo/bar/turkey/mango/noodle
[menu-trail-parents-raw] = foo/bar/turkey/mango/
[title-raw] = noodle

Location on menu: bananana/noodle
[menupath-raw] = bananana/noodle
[menu-trail-parents-raw] = bananana/
[title-raw] = noodle

Location on menu: Not on menu, page title: "wibble"
[menupath-raw] =
[menu-trail-parents-raw] =
[title-raw] = wibble

Could this work?

#7

alexharries - August 4, 2009 - 07:21

A very quick update - the missing slashes in the [menu-trail-parents-raw] token was a bug and not by design - the new version of menutrails includes slashes in the token by renaming it to include "-path", as follows:

[menu-trail-parents-path-raw]

... which means [menu-trail-parents-path-raw]/[title-raw] should work quite well now. Trialling it on http://www.kssdeanery.org now...

#8

mikshimonster - August 11, 2009 - 19:53

In theory, it should work. But it doesn't. I think that the durpal or the modules think that the menu parent path is one below since the menu for the page that you are creating hasn't been created. Thus in pending/unpublished mode, the result is:

first-level/second-level/forth-level
(see that it is missing third-level)

Location on menu: first-level/second-level/third-level/forth-level
[menupath-raw] = first-level/second-level/third-level
[menu-trail-parents-raw] = first-level/second-level/forth-level
[title-raw] = forth-level

Nice try though.

Another one that i tried was [menupath-raw]/[menu-link-title]. It works nicely when it is in pending/unpublished. But when it is published, yes it pastes menu link title twice.

#9

puckbag - September 28, 2009 - 21:26

i hack-solved this by modifying token_node.inc:_menu_titles

this makes [menupath-raw] consistent regardless of selecting "published" on the node. with this implementation, [menupath-raw] should never include the node's own link title. like #8 above, use [menupath-raw]/[menu-link-title] to include the node's link title in the pattern.

old:

      $titles[] = $current['link']['title'];
      if ($current['link']['href'] == "node/". $nid) {
        break;
      }

new:

      if ($current['link']['href'] == "node/". $nid) {
        break;
      }
      $titles[] = $current['link']['title'];

#10

puckbag - September 28, 2009 - 22:23
Status:active» needs review

Here's another approach.

This gets the link titles from the parent menu links referenced directly in the node's menu link (p1-pX) rather than looping over the results of menu_tree_all_data. This also consistently includes the node's own link title as seems to be the intent of this function. Patch attached.

old:

<?php
function _menu_titles($menu_link, $nid) {
 
$tree = menu_tree_all_data($menu_link['menu_name'], $menu_link);

 
// Get mlid of all nodes in path - top-most parent to leaf node.
 
$parents = array();
  for (
$i = 1; $i < MENU_MAX_DEPTH; $i++) {
    if (
$menu_link["p$i"]) {
     
$parents[] = $menu_link["p$i"];
    }
  }
   
 
// Build the titles in this hierarchy.
 
$titles = array();
 
$current = array_shift($tree);      
  while (
$current) {
    if (
in_array($current['link']['mlid'], $parents)) {
     
$titles[] = $current['link']['title'];
      if (
$current['link']['href'] == "node/". $nid) {
        break;
      }
     
// Go deeper in tree hierarchy. 
     
$tree = $current['below'];      
    }
   
// Go to next sibling at same level in tree hierarchy.
   
$current = $tree ? array_shift($tree) : NULL;
  }
  return
$titles;
}  
?>

new:

<?php
function _menu_titles($menu_link, $nid) {
 
// Get mlid of all nodes in path - top-most parent to leaf node.
 
$parents = array();
  for (
$i = 1; $i < MENU_MAX_DEPTH; $i++) {
    if (
$menu_link["p$i"]) {       
     
$parents[] = $menu_link["p$i"];
    }
  }
   
 
// Build the titles in this hierarchy.
 
$titles = array();
  foreach (
$parents as $parent) {
   
$ml = menu_link_load($parent);
   
$titles[] = $ml['link_title'];
  }
  return
$titles;
}
?>

AttachmentSize
token_node.inc-339211-10.patch 1.07 KB
 
 

Drupal is a registered trademark of Dries Buytaert.