0

I am programmatically loading a node of custom content type (i.e. staff) using entity_metadata_wrapper and add a reference to a collection of other nodes and then save the node.

The custom nodes (i.e. of type staff) has a custom a URL, set when the node was created (they are all created manually but, subject to being updated programmatically on regular basis). I also have pathauto module enabled but, I don't need it for this specific scenario.

entity_metadata_wrapper does load the node, assign the references and magically resets the node's custom URL to automatic. Any idea about this behaviour? Is there any way to preserve the custom URL?

Here is the code that loads the node, establish reference and saves the node :

      $node = node_load($staff_drupal_id);
      $wrapper = entity_metadata_wrapper('node', $node);
      $wrapper->field_staff_selected_publication->set($publication_ids);
      $wrapper->save();
1
  • so node_load is nothing but a wrapper for entity_load. cool then, problem is elsewhere.
    – Raf
    Commented Sep 6, 2014 at 21:16

1 Answer 1

0

In case someone else face the same issue, I come across the following

Pathauto uses the following logic (listed by priority) to determine if the Pathauto checkbox should be checked when editing a node:

If the node is a new node, it defaults to having an automatic alias. If the node is not a new node: If the node does not currently have an alias, it assumes that the node was manually un-aliased, so it will default to not have an automatic alias. If the node's current alias matches the alias that Pathauto would generate based on the pattern, then it will default to checked. Otherwise, the checkbox will default to be unchecked. If you are using the Pathauto persistent state module, then once you save a node, the checkbox will remain checked or unchecked regardless of the logic above until you check or uncheck it later.

If you have content you've created before installing Pathauto that you would like to ensure that the checkbox is checked whenever you edit them, then you should use the 'Update URL alias' bulk action on your content listing admin page (admin/content/node).

If you are saving changes to nodes automatically using node_save, you need to specify $node->path['pathauto'] = FALSE; in Drupal 7 or $node->pathauto_perform_alias = FALSE; in Drupal 6 (see http://drupal.org/node/1179988) in order to stop pathauto overwriting any custom paths you might already have for the node.

In Drupal 6

$node->path['pathauto'] = FALSE;

in Drupal 7

$node->pathauto_perform_alias = FALSE;
0

Your Answer

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

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