You are here

function og_vocab_menu_alter in OG Vocabulary 7

Implements hook_menu_alter().

File

./og_vocab.module, line 56
Give each group its own system controlled vocabularies.

Code

function og_vocab_menu_alter(&$callbacks) {

  // Array with menu items, keyed by the ones we need to copy, and the value
  // is the destination menu item.
  $items = array(
    'taxonomy' => array(
      'argument position' => FALSE,
    ),
    'taxonomy/add' => array(
      'argument position' => FALSE,
    ),
    'taxonomy/%taxonomy_vocabulary_machine_name' => array(),
    'taxonomy/%taxonomy_vocabulary_machine_name/list' => array(),
    'taxonomy/%taxonomy_vocabulary_machine_name/edit' => array(),
    'taxonomy/%taxonomy_vocabulary_machine_name/add' => array(),
  );
  $path = drupal_get_path('module', 'taxonomy');
  foreach ($items as $key => $item) {
    $item += array(
      'argument position' => 2,
    );
    $item_path = 'group/%/%/admin/' . $key;
    $original_path = 'admin/structure/' . $key;
    $callbacks[$item_path] = $callbacks[$original_path];
    $callbacks[$item_path]['access callback'] = 'og_vocab_vocabulary_access';
    $access_arguments = array(
      1,
      2,
      'administer taxonomy',
    );
    if ($item['argument position']) {
      $argument_position = 3 + $item['argument position'];

      // Replace the last page argument if it is numeric.
      if (!empty($callbacks[$original_path]['page arguments'])) {
        $page_arguments = $callbacks[$original_path]['page arguments'];
        $pop = array_pop($page_arguments);
        if (is_numeric($pop)) {
          $page_arguments[] = $argument_position;
        }
        $callbacks[$item_path]['page arguments'] = $page_arguments;
      }

      // Set the access arguments.
      $access_arguments[] = $argument_position;

      // Set the title argument.
      if (!empty($callbacks[$item_path]['title arguments'])) {
        $callbacks[$item_path]['title arguments'] = array(
          'taxonomy_vocabulary',
          $argument_position,
        );
      }
    }
    $callbacks[$item_path]['access arguments'] = $access_arguments;
    $callbacks[$item_path]['file path'] = $path;
  }

  // Change the access callback for taxonomy/term/%taxonomy_term/edit
  $callbacks['taxonomy/term/%taxonomy_term/edit']['access callback'] = 'og_vocab_taxonomy_term_edit_access';
  if (variable_get('og_vocab_term_page_access', FALSE)) {
    $callbacks['taxonomy/term/%taxonomy_term']['access callback'] = 'og_vocab_term_page_access';
    $callbacks['taxonomy/term/%taxonomy_term']['access arguments'] = array(
      2,
    );
    $callbacks['taxonomy/term/%taxonomy_term/feed']['access callback'] = 'og_vocab_term_page_access';
    $callbacks['taxonomy/term/%taxonomy_term/feed']['access arguments'] = array(
      2,
    );
  }
}