Drupal - Reorder Content Types in ("/node/add")

Yup! Simply edit your "Navigation" menu (at /admin/structure/menu/manage/navigation) and reorder the menu entries under "Add content". Now when you go to /node/add they'll appear in whatever order you set them in your "Navigation" menu. Example screenshot below. On /node/add they will appear as Basic Page, then Article.

enter image description here


You'd have to resort to a custom module for this as the alphabetical ordering is hard coded into the page callback function node_overview_types() (it's actually built up in _node_types_build() which is called from that function).

Without knowing what you want to sort on it's quite difficult to give a full answer but I'll put the skeleton code in:

function MYMODULE_menu_alter(&$items) {
  // Override the default page callback for the content types page
  $items['admin/structure/types']['page callback'] = 'MYMODULE_node_admin_overview';
}

function MYMODULE_node_admin_overview() {
  // Get the normal page build
  $default_build = node_overview_types();

  // Extract the table rows from the build
  $table_rows = $default_build['#rows'];

  // Perform an operation on these rows to re-order them for your needs
  _some_call_by_reference_sort_function($table_rows);

  // Assign the newly ordered rows back to the page build
  $default_build['#rows'] = $table_rows;

  return $default_build;
}

Make sure you keep your callback function in the main module file otherwise you'll have to mess about with overriding the file key for the original menu item which is never fun.

You'd have to implement your own administration page if you want to be able to change the ordering through the UI.

Tags:

Nodes

7