You are here

domain_menu_access.module in Domain Menu Access 6

Same filename and directory in other branches
  1. 8 domain_menu_access.module
  2. 7 domain_menu_access.module

Extension for Domain module, which allows showing/hiding menu items per domain.

File

domain_menu_access.module
View source
<?php

/**
 * @file
 * Extension for Domain module, which allows showing/hiding menu items per domain.
 */

/**
 * Implementation of hook_help().
 */
function domain_menu_access_help($path, $arg) {
  switch ($path) {
    case 'admin/help#domain_menu_access':
      $output = '<p>' . t("Domain Menu Access is an extension to <a href='@domain_url'>Domain Access</a> module, allowing administrators to configure visitors' access to selected menu items based on current domain they are viewing. It lets administrators decide whether a specific menu item should be hidden on selected domains (regardless of it being enabled by default using standard Drupal functionality), or should it be displayed on some domains even if disabled by default.", array(
        '@domain_url' => url('http://drupal.org/project/domain'),
      )) . '</p>';
      $output .= '<p>' . t('Access to all menu items is managed on standard admin <em>Edit menu item</em> pages in <em>Admin / Site building / <a href="@admin_menus_url">Menus</a></em>, separately for each menu item, using domain checkboxes in <em>Manage item visibility per domain</em> fieldset.', array(
        '@admin_menus_url' => url('admin/build/menu'),
      ));
      $output .= '<p>' . t('Use <em>Show menu item</em> to force displaying items which by default are disabled by <em>Enabled</em> checkbox in <em>Menu settings</em> section. Use <em>Hide menu item</em> to force hiding items which by default are enabled.') . '</p>';
      $output .= '<p>' . t('Note that these settings will be ignored in administration area, which means that all menu items will be enabled or disabled based on default Drupal settings only, as otherwise default state of a menu item could be changed by accident.') . '</p>';
      return $output;
  }
}

/**
 * Implementation of hook_init().
 */
function domain_menu_access_init() {
  module_load_include('admin.inc', 'domain_menu_access');
}

/**
 * Implementation of hook_perm().
 */
function domain_menu_access_perm() {
  return array(
    'administer menus per domain',
  );
}

/**
 * Implementation of hook_translated_menu_link_alter().
 */
function domain_menu_access_translated_menu_link_alter(&$item, $map) {
  global $_domain;

  // Do not hide menu item when we are editing either a specific menu item,
  // or a menu it belongs to, to avoid setting it to hidden it by accident.
  // The challenge here is that we want to keep original $item['hidden']
  // value only in the menu item edit form, while still use value altered
  // by this hook when menu item is displayed outside of edit form.
  // @TODO: Rethink?
  // I still don't quite like this check, although it's already better
  // (again) compared to its previous versions.
  if ($_GET['q'] == 'admin/build/menu-customize/' . $item['menu_name'] || $_GET['q'] == "admin/build/menu/item/{$item['mlid']}/edit") {
    foreach (debug_backtrace() as $trace) {
      if (in_array($trace['function'], array(
        'menu_overview_form',
        'menu_get_item',
      ))) {
        return;
      }
    }
  }

  // Process menu items to be shown per domain.
  if (isset($item['options']['domain_menu_access']['show']) && count($item['options']['domain_menu_access']['show']) && $item['hidden'] == 0) {
    $item['hidden'] = isset($item['options']['domain_menu_access']['show']['d' . $_domain['domain_id']]) && $item['options']['domain_menu_access']['show']['d' . $_domain['domain_id']] ? 0 : 1;
  }

  // Process menu items to be hidden per domain.
  if (isset($item['options']['domain_menu_access']['hide']['d' . $_domain['domain_id']]) && $item['hidden'] == 0) {
    $item['hidden'] = $item['options']['domain_menu_access']['hide']['d' . $_domain['domain_id']] ? 1 : 0;
  }
}