function menu_node_import_values_alter in Node import 6
Implementation of hook_node_import_values_alter().
Look up the menu item using the provided path alias for the node's chosen menu parent.
Here we restructure the values back from the menu: format back into an array for saving.
File
- supported/
menu.inc, line 78 - Support file for the core menu module.
Code
function menu_node_import_values_alter(&$values, $type, $defaults, $options, $fields, $preview) {
static $first_run = TRUE;
// If we are importing nodes and user can administer menus...
if (($node_type = node_import_type_is_node($type)) !== FALSE && user_access('administer menu')) {
if ($first_run) {
$menu_weight = -50;
$first_run = FALSE;
}
else {
$menu_weight = variable_get('node_import_menu_weight', -51);
$menu_weight++;
// If the menu weight gets above the max, roll it over...
if ($menu_weight > 50) {
$menu_weight = -50;
}
}
variable_set('node_import_menu_weight', $menu_weight);
// If the user is trying to configure menu path...
if (isset($values['menu:path']) && drupal_strlen($values['menu:path']) > 0) {
// dpm("Set menu based on path '".$values['menu:path']."' under parent: '".$values['menu:parent']."'");
// Get the menu id using the provided parent node alias
if (($parent = node_import_get_object('menu:path', $values['menu:path'])) || ($parent = menu_node_import_get_parent_from_path($values['menu:path']))) {
$values['menu:parent'] = $parent;
}
else {
// otherwise drop it into the configured menu root.
drupal_set_message("Failed to find an existing menu parent of " . $values['menu:path'] . " - just dropping it in the root of the menu.");
}
// Caching the parent will avoid looking it up the next time
node_import_set_object('menu:path', $values['menu:parent'], $values['menu:path']);
// Every menu needs a title, even if one wasn't provided
$values['menu:link_title'] = isset($values['menu:link_title']) ? $values['menu:link_title'] : $values['title'];
// dpm("Parent of '".$values['title']."' will be '".$values['menu:parent']."'");
$values['menu'] = array(
'parent' => $values['menu:parent'],
'weight' => $menu_weight,
'link_title' => $values['menu:link_title'],
);
}
else {
if (isset($values['menu:link_title']) && drupal_strlen($values['menu:link_title']) > 0) {
// If user configured menu link title, just drop it in the root of the menu
//dpm("Parent of '".$values['menu:link_title']."' will be '".$values['menu:parent']."'");
$values['menu'] = array(
'parent' => $values['menu:parent'],
'weight' => $menu_weight,
'link_title' => $values['menu:link_title'],
);
}
}
}
}