You are here

function pathauto_nodeapi in Pathauto 6

Same name and namespace in other branches
  1. 5.2 pathauto.module \pathauto_nodeapi()
  2. 5 pathauto_node.inc \pathauto_nodeapi()
  3. 6.2 pathauto.module \pathauto_nodeapi()

Implements hook_nodeapi().

5 calls to pathauto_nodeapi()
PathautoBookTokenTestCase::testBookPathAlias in ./pathauto.test
PathautoLocaleTestCase::testLanguageAliases in ./pathauto.test
Test that when an English node is updated, its old English alias is updated and its newer French alias is left intact.
PathautoUnitTestCase::testFeedAliases in ./pathauto.test
Test the feed alias functionality of pathauto_create_alias().
PathautoUnitTestCase::testNoTokensNoAlias in ./pathauto.test
Test that pathauto_create_alias() will not create an alias for a pattern that does not get any tokens replaced.
PathautoUnitTestCase::testUpdateActions in ./pathauto.test
Test the different update actions in pathauto_create_alias().

File

./pathauto.module, line 260
Main file for the Pathauto module, which automatically generates aliases for content.

Code

function pathauto_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch ($op) {
    case 'presave':

      // About to be saved (before insert/update)
      if (!empty($node->pathauto_perform_alias) && isset($node->old_alias) && $node->path == '' && $node->old_alias != '') {

        /**
         * There was an old alias, but when pathauto_perform_alias was checked
         * the javascript disabled the textbox which led to an empty value being
         * submitted. Restoring the old path-value here prevents the Path module
         * from deleting any old alias before Pathauto gets control.
         */
        $node->path = $node->old_alias;
      }
      break;
    case 'insert':
    case 'update':

      // Skip processing if the user has disabled pathauto for the node.
      if (isset($node->pathauto_perform_alias) && empty($node->pathauto_perform_alias)) {
        return;
      }
      _pathauto_include();

      // Get the specific pattern or the default
      if (variable_get('language_content_type_' . $node->type, 0)) {
        $pattern = trim(variable_get('pathauto_node_' . $node->type . '_' . $node->language . '_pattern', FALSE));
      }
      if (empty($pattern)) {
        $pattern = trim(variable_get('pathauto_node_' . $node->type . '_pattern', FALSE));
        if (empty($pattern)) {
          $pattern = trim(variable_get('pathauto_node_pattern', FALSE));
        }
      }

      // Only do work if there's a pattern
      if ($pattern) {
        $placeholders = pathauto_get_placeholders('node', $node);
        $src = "node/{$node->nid}";
        if ($alias = pathauto_create_alias('node', $op, $placeholders, $src, $node->nid, $node->type, $node->language)) {
          $node->path = $alias;
        }
      }
      break;
    case 'delete':
      path_set_alias('node/' . $node->nid);
      path_set_alias('node/' . $node->nid . '/feed');
      break;
  }
}