You are here

function spaces_menu_alter in Spaces 6.3

Same name and namespace in other branches
  1. 6.2 spaces.module \spaces_menu_alter()
  2. 7.3 spaces.module \spaces_menu_alter()
  3. 7 spaces.module \spaces_menu_alter()

Implementation of hook_menu_alter().

File

./spaces.module, line 590

Code

function spaces_menu_alter(&$items) {
  $router_items = array(
    'node/%node',
    'node/%node/edit',
    'user/%user/view',
    'user/%user_uid_optional',
    'user/%user_category/edit',
  );
  foreach (node_get_types('types', NULL, TRUE) as $type) {
    $type_url_str = str_replace('_', '-', $type->type);
    $router_items[] = 'node/add/' . $type_url_str;
  }
  foreach ($router_items as $path) {
    if (isset($items[$path])) {
      $arguments = isset($items[$path]['access arguments']) ? $items[$path]['access arguments'] : array();
      $arguments[] = isset($items[$path]['access callback']) ? $items[$path]['access callback'] : NULL;
      $items[$path]['access callback'] = 'spaces_menu_access';
      $items[$path]['access arguments'] = $arguments;
    }
  }

  // Graft space-specific settings pages into each space type's menu tree.
  $graft = array();
  $graft['features'] = $items['features'];
  foreach ($items as $path => $item) {
    if (strpos($path, 'features/') === 0) {
      $graft[$path] = $item;
    }
  }
  foreach (spaces_types() as $type => $info) {
    if (isset($info['path'])) {
      $graft['features']['type'] = MENU_LOCAL_TASK;
      $graft['features']['access callback'] = 'spaces_access_admin';
      $graft['features']['access arguments'] = array();

      // For any child pages of the graft, increment load arguments by the
      // number of args present in the path.
      $argcount = count(explode('/', $info['path']));
      foreach ($graft as $path => $item) {
        $newitem = $item;
        foreach (array(
          'page arguments',
          'access arguments',
          'title arguments',
        ) as $key) {
          if (!empty($newitem[$key])) {
            foreach ($newitem[$key] as $position => $argument) {
              if (is_numeric($argument)) {
                $newitem[$key][$position] = $newitem[$key][$position] + $argcount;
              }
            }
          }
        }
        $items["{$info['path']}/{$path}"] = $newitem;
      }
      $items["{$info['path']}/features/configure"] = array(
        'title' => 'Configure',
        'description' => 'Configure features for this space.',
        'page callback' => 'drupal_get_form',
        'page arguments' => array(
          'spaces_features_form',
        ),
        'access callback' => 'spaces_access_admin',
        'access arguments' => array(),
        'type' => MENU_DEFAULT_LOCAL_TASK,
        'file' => 'spaces.admin.inc',
      );
      $items["{$info['path']}/features/overrides"] = array(
        'title' => 'Overrides',
        'description' => 'Manage override values for this space.',
        'page callback' => 'drupal_get_form',
        'page arguments' => array(
          'spaces_overrides_form',
        ),
        'access callback' => 'spaces_access_admin_perms',
        'access arguments' => array(
          array(
            'administer spaces',
          ),
        ),
        'type' => MENU_LOCAL_TASK,
        'file' => 'spaces.admin.inc',
        'module' => 'spaces',
      );
    }
  }

  // Overrides of autocomplete callbacks using Views.
  // @TODO: Implement taoxnomy autocomplete callback.
  if (module_exists('views') && isset($items['user/autocomplete'])) {
    $items['user/autocomplete']['page callback'] = 'spaces_user_autocomplete';
    $items['user/autocomplete']['module'] = 'spaces';
    $items['user/autocomplete']['file'] = 'spaces.admin.inc';
  }
}