You are here

function _nodesymlinks_nodeapi_prepare_presave in NodeSymlinks 7

Same name and namespace in other branches
  1. 6 nodesymlinks.inc \_nodesymlinks_nodeapi_prepare_presave()

Implements hook_nodeapi() OP: Prepare & Presave.

See also

nodesymlinks_nodeapi()

2 calls to _nodesymlinks_nodeapi_prepare_presave()
nodesymlinks_node_prepare in ./nodesymlinks.module
Implements hook_node_prepare().
nodesymlinks_node_presave in ./nodesymlinks.module
Implements hook_node_presave().

File

./nodesymlinks.inc, line 175
Main NodeSymlinks callbacks

Code

function _nodesymlinks_nodeapi_prepare_presave(&$node, $op) {

  // Prepare the node for the edit form so that $node->menu always exists.
  $items = array();
  if (isset($node->nid)) {

    // Check all menus if a link does not exist in the default menu.
    $result = db_query("SELECT mlid FROM {menu_links} WHERE module = 'nodesymlinks' AND link_path LIKE :link_path ORDER BY mlid ASC", array(
      ':link_path' => "node/{$node->nid}/mid/%",
    ));
    while ($row = $result
      ->fetchAssoc()) {
      $items[$row['mlid']] = $item = menu_link_load($row['mlid']);
      $items[$row['mlid']]['fragment'] = empty($item['options']['fragment']) ? '' : $item['options']['fragment'];
      if (module_exists('path')) {
        $items[$row['mlid']]['alias'] = db_query("SELECT pid, alias as path FROM {url_alias} WHERE source = :source AND language = :language", array(
          ':source' => $items[$row['mlid']]['link_path'],
          ':language' => $node->language,
        ))
          ->fetchAssoc();
      }
    }
  }

  // Set default values.
  $node->nodesymlinks['items'] = $items;
}