function _menu_import_lookup_path in Menu Export/Import 7
Helper function to find nodes associated with paths. Perform search by title if paths wasn't found.
Parameters
$path: Path (node/* or any other) as described in the input file.
$title: Node's title as described in the input file.
$language: Language of the path.
$options: Array import options provided.
Return value
An array('nid' => '<node_id_or_false>', 'link_path' => '<path_if_exists_or_empty>').
1 call to _menu_import_lookup_path()
- menu_import_parse_line in includes/
import.inc - Parse a line of text containing the menu structure. Only * and - are allowed as indentation characters. Menu item definition may or may not contain details in JSON format.
File
- includes/
import.inc, line 23 - Import functions for menu_import module.
Code
function _menu_import_lookup_path($path, $title, $language, array $options) {
$result = array(
'nid' => FALSE,
'link_path' => '',
'node_view' => FALSE,
'options' => array(),
);
// We need to handle any arguments appended to the path.
$parsed_url = drupal_parse_url($path);
$path = !empty($parsed_url['path']) ? $parsed_url['path'] : '';
if ($parsed_url['query']) {
$result['options']['query'] = $parsed_url['query'];
}
if ($parsed_url['fragment']) {
$result['options']['fragment'] = $parsed_url['fragment'];
}
// Search by alias by default.
$system_url = drupal_lookup_path('source', $path, $language);
if (!$system_url) {
$system_url = $path;
}
$matches = array();
$node_link = preg_match('|^node/(\\d+)(/.*)?|', $system_url, $matches);
// Is there any registered path that is not a node link?
if (!$node_link && drupal_valid_path($system_url)) {
$result['link_path'] = $system_url;
}
elseif ($options['link_to_content']) {
// Link to existing content.
if ($node_link && drupal_valid_path($system_url)) {
$result['link_path'] = $system_url;
$result['nid'] = $matches[1];
$result['node_view'] = empty($matches[2]);
}
else {
$nid = db_select('node', 'n')
->fields('n', array(
'nid',
))
->condition('n.title', $title)
->execute()
->fetchField();
// The node is found.
if ($nid) {
$result['link_path'] = 'node/' . $nid;
$result['nid'] = $nid;
$result['node_view'] = empty($matches[2]);
}
}
}
return $result;
}