You are here

function _chain_menu_access_callback in Chain Menu Access API 8

Same name and namespace in other branches
  1. 6 chain_menu_access.module \_chain_menu_access_callback()
  2. 7.2 chain_menu_access.module \_chain_menu_access_callback()
  3. 7 chain_menu_access.module \_chain_menu_access_callback()
1 string reference to '_chain_menu_access_callback'
chain_menu_access_chain in ./chain_menu_access.module
Prepend the given access callback to the chain.

File

./chain_menu_access.module, line 104
An API module to help client modules chain their access callbacks into other modules' menu items.

Code

function _chain_menu_access_callback() {
  $args = func_get_args();

  // Recover the parameters from the array, plus the $new_access_arguments.
  $parms = array_shift($args);
  if (count($parms) != 5) {

    // Something's wrong (see chain_menu_access_chain() above).
    throw new ChainMenuAccessChainException('Unexpected arguments; client module probably missed calling chain_menu_access_chain() on MENU_DEFAULT_LOCAL_TASK.');
  }
  list($old_access_callback, $new_access_callback, $count, $or, $pass_index) = $parms;
  $new_access_arguments = array_splice($args, 0, (int) $count, array());
  if ($pass_index !== FALSE || $old_access_callback == 'user_access' || is_numeric($old_access_callback)) {

    // Call the $old_access_callback first either if we need to pass its result
    // to the $new_access_callback or if it's a user_access() call or constant
    // number (which would be very quick to evaluate).
    $old_result = (bool) _chain_menu_access_callback_call($old_access_callback, $args);
    if ($pass_index !== FALSE) {
      $new_access_arguments[$pass_index] = $old_result;
    }
    elseif ($or == $old_result) {

      // Do shortcut evaluation on the second operand first!
      return $or;
    }
  }
  $new_result = _chain_menu_access_callback_call($new_access_callback, $new_access_arguments);

  // Do normal shortcut evaluation on the first operand (or simply return the
  // result if we have a $pass_index).
  if ($pass_index !== FALSE || $or == $new_result) {
    return $new_result;
  }

  // Call $old_access_callback if we haven't called it yet.
  if (!isset($old_result)) {
    $old_result = _chain_menu_access_callback_call($old_access_callback, $args);
  }
  return $old_result;
}