Skip to content

Instantly share code, notes, and snippets.

@omerida
Created June 6, 2014 17:55
Show Gist options
  • Save omerida/7f7fae2f9273d26898d1 to your computer and use it in GitHub Desktop.
Save omerida/7f7fae2f9273d26898d1 to your computer and use it in GitHub Desktop.
Drupal hooks for finding orphaned nodes
<?php
/**
* Implements hook_menu()
*/
function node_orphaned_menu() {
$items['admin/content/node-orphaned'] = array(
'page callback' => 'node_orphaned_list',
'title' => 'Orphaned Pages',
'access arguments' => 'administer nodes',
'type' => MENU_LOCAL_TASK,
);
return $items;
}
function node_orphaned_list() {
$result = db_query("SELECT node.title AS node_title, node.nid AS nid, node.created AS node_created, CONCAT('node/', node.nid) as node_path, ml.link_path
FROM node
LEFT JOIN menu_links ml ON link_path = concat('node/', node.nid)
WHERE (node.type IN ('page') AND link_path IS NULL)
ORDER BY node_created DESC");
$table['header'] = array('Edit', 'Title', 'View');
$table['rows'] = array();
// Result is returned as a iterable object that returns a stdClass object on each iteration
foreach ($result as $record) {
$table['rows'][] = array(
l('Edit', 'node/' . $record->nid . '/edit'),
$record->node_title,
l('View', 'node/' . $record->nid),
);
}
drupal_set_title('Pages without Menu entries');
return theme('table', $table);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment