Since upgrading to Pathauto 5.x-2.1, it appears that nodes that are saved through the Workflow tab or through Views Bulk Operations -- both of which call node_save() -- no longer generates a path alias for the node.

If the node is edited the path then does get generated correctly. The issue is that we are using Workflow to designate paths, i.e., [workflow-current-state-name]/[nid], but these used to get generated whenever one used the Worfklow menu tab or Views Bulk Operations.

Any ideas what could be wrong?

CommentFileSizeAuthor
#10 pathauto-225554-10.patch1.1 KBdropcube

Comments

greggles’s picture

I just looked and on line 655 or so of node.module node_save does invoke the insert and/or update hook of nodeapi which is what Pathauto responds to.

But, there was some code I introduced so that pathauto will only try to run if there is a pattern for this node type or if there is a default pattern. Perhaps some of that logic isn't working correctly? Could you take a look at that?

btully’s picture

thanks for the quick response greggles.

FWIW, I reverted back to 5.x-2.0 and the aliases are getting generated again.

Under my Pathauto settings there is both a pattern set for this specific node type, [workflow-current-state-name]/[nid], and a default pattern set for blank node types, [type-name]/[nid]. Pathauto's general settings are set so that the Update Action creates a new alias and deletes the old one. But with 5.x-2.1, at least in terms of Workflow module and changes in workflow state, the new aliases aren't getting created.

Is it possibly a module weight issue, i.e., maybe Pathauto needs to have a higher system weight than Workflow?

greggles’s picture

Perhaps. Pathauto needs to be heavier than modules in order to more reliably extract taxonomy data.

Can you provide a really simple workflow to demonstrate this problem? I'd love to test it but other than "install pathauto and workflow or views bulk operations" I don't know where to go next...

btully’s picture

we have a node type called "article" with a corresponding workflow which has states "Drafts", "Editorial", "Published", and "Published Archive".

Our Pathauto config is set up to use [workflow-current-state-name]/[nid] for this node type. With Pathauto 5.x-2.0, when we use the workflow tab to change a node's workflow state from "Drafts" to "Editorial" and submit, Pathauto automatically generates the new alias, changing the path from "drafts/123" to "editorial/123". Since we have verbose mode on it even notifies the user when a new alias has been generated using the standard drupal_set_message().

However, with Pathauto 5.x-2.1, the alias does not get generated and no message appears after the workflow state change is submitted from within the Workflow tab. It seems the only time an alias is generated is when the node/edit form is submitted. This differs from previous iterations of Pathauto as we were able to generate the new alias from both the node/edit page as well as the workflow tab submit.

hope that's informative enough. please let me know if you need more info or if there's anything I can do to help.

regards,
brian

dropcube’s picture

I have a similar issue when a node is created programmatically using drupal_execute.

At pathauto_nodeapi we have:


          if ($node->pathauto_perform_alias || !user_access('create url aliases')) {
            // ... create the alias for the node ... 
          } 

At pathauto_form_alter we have:

  if (isset($form['#id']) && ($form['#id'] == 'node-form') && arg(0) == 'node') {

If the node is being created programmatically, then arg(0) won't be 'node', and therefore $node->pathauto_perform_alias won't exists. The condition at pathauto_nodeapi fails and the path won't be created.

I don't understand why is required to check arg(0) == 'node'

greggles’s picture

That's because of http://drupal.org/node/217992

I'd be happy to have a better solution, but that's why we need something...

btully’s picture

any chance we could try this?

<?php


          if ($node->pathauto_perform_alias || !isset($node->pathauto_perform_alias) || !user_access('create url aliases')) {
            // ... create the alias for the node ...
          }
?>

seems like the main difference is that the previous version that's working for me (5.x-2.0) allowed an alias to get generated if $node->pathauto_perform_alias was not set, i.e., if the node was saved other than through the node edit page or programmatically. Can we add back in the !isset($node->pathauto_perform_alias) in pathauto_nodeapi?

greggles’s picture

Did you test that? I believe that when a checkbox is not checked then the $node->pathauto_perform_alias will be not set? Checkboxes come through as either set or not set instead of TRUE vs. FALSE, right?

btully’s picture

haven't had a chance to test it yet but will try to today.

in terms of the checkboxes, you are correct. If a checkbox is not checked it's value is not set vs. being set to FALSE.

so with the current requirement for $node->pathauto_perform_alias to be set to TRUE, this means that an alias can only get generated from the node edit form and only if the "Automatic alias" checkbox is checked.

This would explain why the alias no longer gets generated from the Workflow tab or through Views Bulk Operations as those are simply calling node_save().

How about adding a hidden field to the node edit form so that in addition to the Automatic alias checkbox field it gives us another value to compare, e.g.

<?php

 function pathauto_form_alter($formid, &$form) {
  
    ...

     $form['path']['pathauto_perform_alias'] = array('#type' => 'checkbox',
        '#title' => t('Automatic alias'),
        '#default_value' => TRUE,
        '#description' => $output,
        '#weight' => 0
      );

      $form['path']['pathauto_node_form'] = array('#type' => 'hidden',
        '#value' => TRUE,
        '#weight' => 0
      );
    }
  }
}
?>

and then in pathauto_nodeapi

<?php
 
          if (
              // if it's a node edit form and the checkbox is checked
              ($node->pathauto_node_form && $node->pathauto_perform_alias) || 
              // if it's a node edit form and the user doesn't have access to the checkbox 
              ($node->pathauto_node_form && !user_access('create url aliases')) || 
              // if it's NOT a node edit form, we need to allow the path alias to be generated
              !isset($node->pathauto_node_form)
          ) {

?>

i'll try to test this today

regards,
brian

dropcube’s picture

StatusFileSize
new1.1 KB

When checkboxes are checked, they come with a value of int(1), if unchecked, int(0), but in any case they are set. So, IMHO, is not required to add an extra hidden field to the form.

An alias should be created only:

  1. If a checkbox has been provided to the user AND has been checked
  2. if a checkbox has NOT been provided to the user. This includes the cases when nodeapi was invoked programmatically ( i.e., calling node_save) and the case when the user doesn't have the perms to create aliases

Note: If the user doesn't have the perms to create aliases, then the checkbox is not provided. This check is implemented in pathauto_form_alter. For this reason, this case in included in 2.

The code in looks like this:

          // Only create an alias if the checkbox was not provided or if the checkbox was provided and is checked 
          if ( !isset($node->pathauto_perform_alias) || $node->pathauto_perform_alias) {
            $placeholders = pathauto_get_placeholders('node', $node);
            $src = "node/$node->nid";
            $alias = pathauto_create_alias('node', $op, $placeholders, $src, $node->nid, $node->type);
          }

Implementing this, aliases can be created even when nodes are created programmatically with node_save or drupal_execute.

I still don't think that the check arg(0) == 'node' in pathauto_form_alter is required, but with this patch it doesn't matter.

I confirm that this issue is critical, there may be many sites using pathauto that create nodes programmatically.

dropcube’s picture

Version: 5.x-2.1 » 5.x-2.x-dev
Status: Active » Needs review
btully’s picture

thanks for the patch dropcube. this seems to have resolved the issue for us when updating a node through the Workflow tab and/or through Views Bulk Operations.

Any chance of this patch making it into the release?

One thing I sort of miss is the verbose option telling me the aliases have been generated. It looks as though this has been removed if one is generating the alias programmatically. But certainly not a high priority compared to not being able to generate an alias programmatically.

greggles’s picture

@btully - yes, I'm testing this out on all my sites now. Assuming it (continues) working I'll apply it in a day or so.

I'm not sure about the verbose thing. Can you open a new issue for that?

btully’s picture

thanks so much greggles and dropcube. much appreciated!

jpsalter’s picture

The patch in #10 fixed my pathauto problems for nodes generated using mailhandler.module.

Also, I have a lot of custom import functions that create nodes. I have not tested them yet - hopefully this fixes them too.

greggles’s picture

Title: PathAuto no longer creating aliases on node_save()? » Pathauto no longer creating aliases on node_save()
Status: Needs review » Fixed

Committed to both 5.x and HEAD. Thanks dropcube!

If y'all can upgrade to the dev version (tomorrow, after it is re-rolled) and test it out then I can tag and roll a 5.x-2.2 release.

btully’s picture

greggles -

I updated to the dev version today and tested it out quite a bit and it seems to work like a charm. Aliases are once again getting generated on node_save via the Workflow tab and/or via Views Bulk Operations.

Thanks again to you and dropcube for resolving this so quickly! :)

samc’s picture

Problem for me was nodes created via the Blog API (blogapi). I haven't tested thoroughly but the node_save issue appears to be fixed.

Thanks!

jaharmi’s picture

I’m also seeing something similar with Pathauto 2.1 when I submit new story nodes, published to my front page, via MarsEdit 2.1 on Mac OS X. So, I’m using Blog API to do my submissions, and my new nodes are missing the automatically-generated path.

This is similar to a previous problem I’d seen with Pathauto (1.x?) earlier under Drupal 5.x, which was subsequently fixed.

jaharmi’s picture

Update: I submitted a new story node to my site while Pathauto 2.1 was installed. It didn't generate a path.

I updated to Pathauto 5.x-2.x dev version from earlier in March, updated the story node via MarsEdit (using Blog API) and the path was generated for it.

HTH, thanks!

greggles’s picture

Status: Fixed » Postponed (maintainer needs more info)

@jaharmi - note that this issue is "fixed" and should work in the current 5.x-2.x-dev. Can you test and confirm that it works using that version?

greggles’s picture

Status: Postponed (maintainer needs more info) » Fixed

Guess so.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

allella’s picture

Downloaded 5.x-2.x-dev and it took care of the issue for me. Thanks.