Skip to content

Instantly share code, notes, and snippets.

@dooug
Last active September 11, 2023 19:59
Show Gist options
  • Save dooug/b102a683d4e4854defba to your computer and use it in GitHub Desktop.
Save dooug/b102a683d4e4854defba to your computer and use it in GitHub Desktop.
Generate list of pages in Drupal
<?php
/**
* @file gets "path, title" csv format of entries from node, menu_links, menu_router
*
* run from within drupal project root: drush scr generate_list.php
*/
// Bootstrap Drupal
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$list = array(array("path", "title"));
$result = db_query('select path, title from menu_router')->fetchAll();
$router_items = array();
foreach ($result as $obj) {
$router_items[] = get_object_vars($obj);
}
$list = array_merge($list, $router_items);
$result = db_query('select link_path, link_title from menu_links')->fetchAll();
$items = array();
foreach ($result as $obj) {
$items[] = get_object_vars($obj);
}
$list = array_merge($list, $items);
// find nodes
$res = db_query('select nid from node')->fetchAll();
$nodes = array();
foreach ($res as $obj) {
$node = node_load($obj->nid);
$arr = array(drupal_get_path_alias('node/' . $node->nid), $node->title);
$nodes[] = $arr;
}
$list = array_merge($list, $nodes);
// print csv
foreach ($list as $row) {
print_r(implode(',',$row));
print "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment