You are here

function domain_path_node_insert in Domain Path 7

Implements hook_node_insert().

1 call to domain_path_node_insert()
domain_path_node_update in ./domain_path.module
Implements hook_node_update().

File

./domain_path.module, line 390
Path alias handling for multiple domains.

Code

function domain_path_node_insert($node) {
  if (empty($node->domain_path)) {
    return;
  }

  // If not set to revert, then save changes.
  if (empty($node->domain_path['domain_path_delete'])) {
    $paths = array();
    unset($node->domain_path['domain_path_delete']);
    foreach ($node->domain_path as $domain_id => $alias) {

      // Attempt to retreive the path.
      $conditions = array(
        'source' => "node/{$node->nid}",
        'language' => $node->language,
        'domain_id' => $domain_id,
      );
      $path = domain_path_path_load($conditions);
      if (!$path) {
        $path = array();
      }

      // Set the path alias.
      $path['alias'] = $alias;

      // Fill in missing pieces.
      $path += array(
        'dpid' => NULL,
        'domain_id' => $domain_id,
        'source' => "node/{$node->nid}",
        'language' => isset($node->language) ? $node->language : LANGUAGE_NONE,
        'entity_type' => 'node',
        'entity_id' => $node->nid,
      );

      // Delete old alias if user erased it.
      if (!empty($path['dpid']) && empty($path['alias'])) {
        domain_path_path_delete($path['dpid']);
      }
      elseif (!empty($path['alias'])) {
        $paths[$domain_id] = $path;
      }
    }

    // Save the paths.
    if (!empty($paths)) {
      domain_path_save_paths($paths);
    }
  }
  else {
    domain_path_node_delete($node);
  }
}