You are here

function admin_menu_clone_items in Admin 6

Helper to clone portions of the menu tree to a duplicate location.

1 call to admin_menu_clone_items()
admin_menu_alter in ./admin.module
Implementation of hook_menu_alter().

File

./admin.module, line 174

Code

function admin_menu_clone_items($search, $replace, $items) {
  $offset = count(explode('/', $replace)) - count(explode('/', $search));
  $clone = array();
  foreach ($items as $path => $item) {
    if (strpos($path, $search) === 0) {
      $clone_path = str_replace($search, $replace, $path);

      // Adjust argument offsets if the search and replace paths have a
      // different arg counts.
      if ($offset != 0) {
        foreach (array(
          'page arguments',
          'access arguments',
          'load arguments',
          'title arguments',
        ) as $arg_key) {
          if (!empty($item[$arg_key])) {
            foreach ($item[$arg_key] as $k => $v) {
              if (is_numeric($v)) {
                $item[$arg_key][$k] = $v + $offset;
              }
            }
          }
        }
      }
      $clone[$clone_path] = $item;
    }
  }
  return $clone;
}