0

I am having a problem saving nodes programatically. I am attempting to save nodes that use the following pathauto pattern for an alias:

[node:og-group-ref:0:url:relative]/[node:menu-link:parents:join-path]/[node:title]

Both the first and last token work fine both ways. However, the middle token - [node:menu-link:parents:join-path] - returns empty when saving through a script and populates fine when saving through the UI.

I've inspected $node object that is being passed through in each case and they are identical, except for $node->path. When saving through the UI the $node->path value looks something like this (copied from devel dsm message):

[path] => Array
    (
      [alias] => communications/some-person
      [pid] => 153
      [source] => node/100
      [language] => und
      [pathauto] => 1
    )

However, when saving programatically $node->path looks like this:

[path] => Array
          (
            [pathauto] => 1
            [alias] => 
          )

As you can see, its missing data that is present when saving through the UI, and I suspect that data is needed to correctly parse the token.

Anyone have any idea why these two would be different or why the [node:menu-link:parents:join-path] token doesn't work when saving through the script?

If it matters, script is pretty straight-forward:

<?php
$nids = db_query('SELECT nid FROM {node} where nid = 100')->fetchCol();
foreach (node_load_multiple($nids) as $node) {
  echo "Saving node " . $node->nid . "\r\n";
  print_r($node);
  node_save($node);
}

Thanks in advance.

1 Answer 1

1

For anyone that might find this in the future, this is related to this issue:

http://drupal.org/node/1534356

Still trying to figure out a workaround for my scenario, but this is the cause.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.