You are here

advanced_menu_core.module in Advanced Menu 7

Same filename and directory in other branches
  1. 6.x core/advanced_menu_core.module

Provides advanced menu permissioning.

File

core/advanced_menu_core.module
View source
<?php

// $Id: advanced_menu_core.module $

/**
 * @file
 * Provides advanced menu permissioning.
 */

/**
 * Implementation of hook_permission().
 */
function advanced_menu_core_permission() {
  return array(
    'administer advanced menu permissions' => array(
      'title' => t('Administer Advanced Menu Permissions'),
      'description' => t('Set permissions for the Advanced Menu module.'),
    ),
  );
}

/**
 * Implements hook_menu().
 */
function advanced_menu_core_menu() {
  $items['admin/structure/menu/advanced'] = array(
    'title' => 'Advanced Menus',
    'description' => 'Description of Advanced Menus and a small reminder that Advanced Menus is active.',
    'page callback' => 'advanced_menu_core_about_page',
    'access callback' => 'advanced_menu_core_access',
    'access arguments' => array(
      'administer menu',
      'admin',
    ),
    'file' => 'advanced_menu_core.admin.inc',
    'type' => MENU_LOCAL_TASK,
    'weight' => 10,
  );
  return $items;
}

/**
 * Implementation of hook_menu_alter().
 */
function advanced_menu_core_menu_alter(&$callbacks) {
  $callbacks['admin']['access callback'] = 'advanced_menu_core_access';
  $callbacks['admin']['access arguments'] = array(
    'administer menu',
    'basic',
  );
  $callbacks['admin/structure']['access callback'] = 'advanced_menu_core_access';
  $callbacks['admin/structure']['access arguments'] = array(
    'administer menu',
    'basic',
  );
  $callbacks['admin/structure/menu']['page callback'] = 'advanced_menu_core_overview_page';
  $callbacks['admin/structure/menu']['file'] = 'advanced_menu_core.admin.inc';
  $callbacks['admin/structure/menu']['file path'] = drupal_get_path('module', 'advanced_menu_core');
  $callbacks['admin/structure/menu']['access callback'] = 'advanced_menu_core_access';
  $callbacks['admin/structure/menu']['access arguments'] = array(
    'administer menu',
    'basic',
  );
  $callbacks['admin/structure/menu/list']['page callback'] = 'advanced_menu_core_overview_page';
  $callbacks['admin/structure/menu/list']['file'] = 'advanced_menu_core.admin.inc';
  $callbacks['admin/structure/menu/list']['file path'] = drupal_get_path('module', 'advanced_menu_core');
  $callbacks['admin/structure/menu/list']['access callback'] = 'advanced_menu_core_access';
  $callbacks['admin/structure/menu/list']['access arguments'] = array(
    'administer menu',
    'basic',
  );
  $callbacks['admin/structure/menu/add']['access callback'] = 'advanced_menu_core_access';
  $callbacks['admin/structure/menu/add']['access arguments'] = array(
    'administer menu',
    'admin',
  );
  $callbacks['admin/structure/menu/settings']['access callback'] = 'advanced_menu_core_access';
  $callbacks['admin/structure/menu/settings']['access arguments'] = array(
    'administer menu',
    'admin',
  );
  $callbacks['admin/structure/menu/item/%menu_link/delete']['access callback'] = 'advanced_menu_core_access';
  $callbacks['admin/structure/menu/item/%menu_link/delete']['access arguments'] = array(
    'administer menu',
    'edit item',
    4,
  );
  $callbacks['admin/structure/menu/item/%menu_link/edit']['access callback'] = 'advanced_menu_core_access';
  $callbacks['admin/structure/menu/item/%menu_link/edit']['access arguments'] = array(
    'administer menu',
    'edit item',
    4,
  );
  $callbacks['admin/structure/menu/item/%menu_link/reset']['access callback'] = 'advanced_menu_core_access';
  $callbacks['admin/structure/menu/item/%menu_link/reset']['access arguments'] = array(
    'administer menu',
    'edit item',
    4,
  );
  $callbacks['admin/structure/menu/manage/%menu']['access callback'] = 'advanced_menu_core_access';
  $callbacks['admin/structure/menu/manage/%menu']['access arguments'] = array(
    'administer menu',
    'edit menu',
    4,
  );
  $callbacks['admin/structure/menu/manage/%menu/add']['access callback'] = 'advanced_menu_core_access';
  $callbacks['admin/structure/menu/manage/%menu/add']['access arguments'] = array(
    'administer menu',
    'edit menu',
    4,
  );
  $callbacks['admin/structure/menu/manage/%menu/delete']['access callback'] = 'advanced_menu_core_access';
  $callbacks['admin/structure/menu/manage/%menu/delete']['access arguments'] = array(
    'administer menu',
    'edit menu',
    4,
  );
  $callbacks['admin/structure/menu/manage/%menu/edit']['access callback'] = 'advanced_menu_core_access';
  $callbacks['admin/structure/menu/manage/%menu/edit']['access arguments'] = array(
    'administer menu',
    'edit menu',
    4,
  );
}

/**
 * Implementation of hook_access().
 */
function advanced_menu_core_access() {
  global $user;
  $roleMenus = array();
  $args = func_get_args();
  $retVal = user_access($args[0]);
  if (module_exists('advanced_menu_menu_admin')) {
    $roleMenus = _advanced_menu_menu_admin_menus();
  }
  if (count($args) > 1) {
    switch ($args[1]) {
      case 'anonymous':
        $retVal = TRUE;
        break;
      case 'edit node':
      case 'basic':
        if (count($roleMenus) > 0 || user_access($args[0])) {
          $retVal = TRUE;
        }
        break;
      case 'admin':
        $retVal = user_access($args[0]);
        break;
      case 'edit menu':
      case 'edit item':
        if (isset($roleMenus)) {
          $retval = FALSE;
          if (isset($roleMenus[$args[2]['menu_name']])) {
            $retVal = TRUE;
          }
        }
        break;
    }
  }
  return $retVal;
}

Functions

Namesort descending Description
advanced_menu_core_access Implementation of hook_access().
advanced_menu_core_menu Implements hook_menu().
advanced_menu_core_menu_alter Implementation of hook_menu_alter().
advanced_menu_core_permission Implementation of hook_permission().