Skip to content

Instantly share code, notes, and snippets.

@amcgowanca
Last active August 29, 2015 14:08
Show Gist options
  • Save amcgowanca/ee3f1d89fd06e51697c1 to your computer and use it in GitHub Desktop.
Save amcgowanca/ee3f1d89fd06e51697c1 to your computer and use it in GitHub Desktop.
<?php
/**
* Returns the node identifier should the path be a node viewing path.
*
* Note: This function returns FALSE for all node action or local task paths
* such as node/[nid]/edit.
*
* Furthermore, a node alias may be specified as $path which will perform a path
* normalization allowing for the node system path to be retrieved and parsed.
*
* @param string $path
* The path to attempt to retrieve the node id for.
*
* @return mixed
* Returns the node id as an integer, otherwise FALSE.
*/
function MY_MODULE_path_is_node_view($path) {
$path = drupal_get_normal_path($path);
if (preg_match('|node/([0-9]+)?|', $path, $matches)) {
return isset($matches[1]) && is_numeric($matches[1]) ? intval($matches[1]) : FALSE;
}
return FALSE;
}
@amcgowanca
Copy link
Author

For a complex usage and multiple variations, see http://github.com/amcgowanca/drupal_uuid_menu_links.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment