Hi there. I'm still working on evaluating the workbench suite as the modules we will use to manage content and organize our site structure.

I've set up workbench access to use Automated Section Assignment and I've encountered something that isn't working as I expected.

I'm not certain if it's because I'm misinterpreting the way things are supposed to work (which is why I've filed it under feature request) or if it's a bug. My thinking is that I misinterpreted it and things are working as expected but I want to be certain, and if this is the case, submit a feature request.

Currently I have a taxonomy set up with one vocabulary, which here I'll call UniversityName. Inside this vocabulary I have created added two terms:

  • UniversityName
    • ComputerScience
      • FacultyMemberName

As you can see FacultyMemberName term is a child of the ComputerScience term.

The URL alias pattern I've set up in the Pathauto module is as follows:

[node:workbench-access-sections]/[node:title]

When I created a basic page calling it Research and assigned it to the FacultyMemberName my expectation was that the alias would be:

http://drupalwb.mysite.com/computerscience/facultymembername/research

However, the result is actually:

http://drupalwb.mysite.com/facultymembername/research

Do you think it is a configuration error and I've missed something or done something incorrectly, or is this the intended way that it should function?

If this is the intended way it should function, do you think it would be reasonable to in a future release provide functionality such that an alias could be created that uses the hierarchy of the editorial section to which a piece of content is assigned?

Thanks,
Pablo

CommentFileSizeAuthor
#2 1332512-hierarchical-tokens.patch2.79 KBagentrickard

Comments

agentrickard’s picture

It is not an error. It's a reasonable Feature Request, which I would state as follows:

  • Provide a new token that prints the entire hierarchy of the active access section.
  • [node:workbench-access-section-hierarchy] should return parent/child/section instead of section, which is how [node:workbench-access-sections] functions currently.

I do believe that if you are using Token module, the current token may return an array that you can use in this way, but I'm not sure of that.

agentrickard’s picture

Assigned: Unassigned » dave reid
Status: Active » Needs review
StatusFileSize
new2.79 KB

Here's a patch that makes this work, sort of. What it does is run the section assignments and take the deepest child assignment and makes that a token.

Need to get davereid's input before this gets committed.

Status: Needs review » Needs work

The last submitted patch, 1332512-hierarchical-tokens.patch, failed testing.

agentrickard’s picture

That test fail is an infrastructure problem, not the patch itself.

Pablo Gosse’s picture

Thanks for the quick response and the patch. Looks good with one issue, however I don't think the issue relates to the workbench_access module.

I updated the alias patterns to use [node:workbench-access-section-hierarchy]/[node:title] but when I create a page instead of the alias being written as parent/child/section/node it is written as parentchildsection/node so it appears Pathauto is stripping the '/' from the alias when it's being created.

I think the cause of this is outside the workbench_access module though since the value returned from workbench_access_tokens is correct and if I replace '/' with '-' in the implode call on the sections hierarchy the '-' is preserved in the alias with the result being parent-child-section/node.

I'm going to dig around and will file a bug report in Pathauto once I pinpoint the cause.

Thanks,
Pablo

Pablo Gosse’s picture

Scratch that as being a problem with pathauto. Just looking through the pathauto code and read something that prompted me to look into the config a little more where I just had to disable removal of the '/' in the alias and it works perfectly.

Thanks again.

Cheers,
Pablo

agentrickard’s picture

Well, this may not be the right solution, which is why I asked Dave Reid to take a look.

dave reid’s picture

Hrm didn't notice this before. Will be taking a look later today.

dave reid’s picture

The proper solution would be to provide an 'array' token in which the array values are the lineage of the section, starting with the 'root' and ending with the parent. See #1266928: Add [term:parents] and [menu-link:parents] array tokens for an example of how this should be implemented.

The problem here becomes what happens when 'Allow multiple section assignments' is enabled and a node is assigned to more than one section. The solution may be that this token just doesn't work if a node has multiple sections.

agentrickard’s picture

Title: Vocabulary hierarchy in path (not sure if it should be a bug or feature request) » Vocabulary hierarchy in path

Or we pick one...

Pablo Gosse’s picture

Hi again. I think I've found a small bug in the patch in #2 but it is an easy fix. Unfortunately I don't have source control set up yet so I can't generate a patch file but I've provided the updated code and an outline of the bug below.

Here is the problem code, from the 'workbench-access-section-hierarchy' case in the switch statement in the workbench_access_tokens function:

foreach ($hierarchy as $value) {
  $list[] = $value['name'];
}
$list[] = $name;

The problem arises when a node is created in a section that is the root of a vocabulary. In this case the section will be printed twice in the alias since it gets assigned once as part of the hierarchy, and again as the section name once the iteration of the hierarchy is complete.

The fix for this is just to wrap the foreach in a check to see if the hierarchy has more than one element:

if (count($hierarchy) > 1) {
  foreach ($hierarchy as $value) {
    $list[] = $value['name'];
  }
}
$list[] = $name;

I created a clean instance of Drupal with only workbench access and pathauto, as well as the necessary underlying modules, installed, and was able to reproduce it there using the default 'Tags' vocabulary.

I'm not sure if this is the best practice approach as I'm still relatively new to coding standards and structure in Drupal but it seems to fix the problem. Look forward to your response as to whether this is the correct fix.

Thanks,
Pablo

Pablo Gosse’s picture

Hi again @Dave Reid and @agentrickard.

I discovered this week that my suggested fix in #11 above was erroneous.

The problem stems from the fact that when using the name of a vocabulary as the section assignment for a node, the call to workbench_access_get_parents returns the vocabulary name as its own parent. After the iteration through the hierarchy the name of the vocabulary is appended to the $list variable and the result is the duplication of the vocabulary name.

The fix for this could be applied in one of two places, so I'm looking for advice as to which you think it should be:

1. workbench_access_tokens() function in workbench_access.tokens.inc

If the fix is applied here, one would need to modify the following:

foreach ($hierarchy as $value) {
  $list[] = $value['name'];
}

to this:

foreach ($hierarchy as $value) {
  if ($access_id != $value['name']) {
    $list[] = $value['name'];
  }
}

2. workbench_access_get_parents() function in workbench_access.module

If the fix is applied here, one would need to modify the following:

if (isset($info['children']) && in_array($access_id, $info['children']) && isset($active['active'][$id])) {

to this:

if ($access_id != $id && isset($info['children']) && in_array($access_id, $info['children']) && isset($active['active'][$id])) {

Both of these methods yield the same end result but I lean toward #2 as being the correct fix since the vocabulary name is not its own parent and so should not be returned as part of the $parents array when workbench_access_get_parents is called.

Thoughts?

Thanks,
Pablo

dave reid’s picture

Priority: Normal » Major

Upgrading in priority to fix this weekend.

dave reid’s picture

Think I might have a viable solution worked out as an alternative.

Pablo Gosse’s picture

Awesome! Look forward to seeing it, Dave.

Cheers,
Pablo

richardhayward’s picture

Hi - I'm wondering if there is any progress on this issue. We are running this module on one of our sites and this issue sometimes causes some problems for us when maintaining or adding new content. I would appreciate your time to progress this if possible.

Pablo Gosse’s picture

Hi richardhayward. The solution I've implemented and which has worked fine for us thus far (both on creation and updating of content) has been as follows:

1. Apply patch from http://drupal.org/node/1319988#comment-5175432

2. Apply patch from http://drupal.org/node/1332512#comment-5210518

3. Apply one of the changes from http://drupal.org/node/1332512#comment-5520420. I use change #2 from this post.

Then I use the following pattern in Pathauto configuration to create the correct URL:

[node:workbench-access-section-hierarchy]/[node:title]

This will resolve the 'unassigned' issue, and will also ensure the correct hierarchy structure in the url.

Not sure what the status is of these changes being packaged up into an official release, but until that happens this should at least resolve the issue for you.

Hope that helps.

Thanks,
Pablo

richardhayward’s picture

Thanks Pablo, we appreciate your response and work on this. Its good to know the fix is working. For longer term continuity, it would be a good idea to get the changes into a module update.

Taxoman’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
agentrickard’s picture

See also #1794980: Update Workbench Information block to include full hierarchy for a possible helper function to make this easier.

Pablo Gosse’s picture

@agentrickard, the helper function you reference, does this address the issue of hierarchy in the path in a different manner? Or does it just address the path as it's presented in the Workbench Information block?

Thanks,
Pablo

agentrickard’s picture

The helper function can be used by the token to generate the hierarchy. It returns an array that you can display as you see fit.

blainelang’s picture

Is there any update on this issue? Even the linked issue in #20 above appears to have gone dormant. There was a recent 7.x-1.2 release (Jan 2013) but it does not appear to have included any fix for the pathauto token issue.

Pablo Gosse’s picture

@blainelang, I don't think there has been an update on this issue. I'm currently in the process of upgrading out of date modules in our Drupal instance and I had to follow the steps I outlined in #17 above (http://drupal.org/node/1332512#comment-6309158) to have things work correctly.

I've PM'd Dave Reid to see what needs to happen to get these changes into a future release.

Cheers,
Pablo

Pablo Gosse’s picture

Component: Miscellaneous » Code

Setting this issue to properly reflect the 'Code' component rather than 'Miscellaneous'.