Quantcast
Viewing all articles
Browse latest Browse all 294794

hook_menu_alter path

API page: http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_menu_alter/7

in my module i need to process permission to add content of type "company"

in process function i want to check user vars and return true or redirect in callback

for it i write

<?php
/**
* Implements hook_menu_alter().
*/
function ioncode_menu_alter(&$items) {

$items['node/add/company/']['access callback']='ioncode_companyadd_access';

}
?>

and callback

<?php
function ioncode_companyadd_access($op, $type, $account = NULL) {

// original access

$args = func_get_args();
 
$original_access = call_user_func_array('node_access', $args);
  if (!
$original_access) {
  return
false;
 
  }
 
// some bug !!!
 
if (arg(2)!='company'){
  return
$original_access;
  }
 
 
  global
$user;
 
$view = views_get_view('member');
 
$view->set_display('page_1');
 
$view->set_arguments(array($user->uid));
 
$view->pre_execute();
 
$view->execute();

var_dump(array(arg(2), $args, $original_access, $view->result));
// user's company exists
//var_dump($view->result);
if (empty($view->result)){
  return
true;
}
else {
drupal_goto('node/1055');
}
}
?>

here i use

<?php
 
// some bug !!!
 
if (arg(2)!='company'){
  return
$original_access;
  }
 
?>

because requests to url
  • "/node/add"
  • "/node/add/blablabla"
  • "/node/add/anotherexistingtype"
  • "/node/add/andsoon"

evaluates by controller my callback function "ioncode_companyadd_access"

why? i think this callback MUST be evaluated only in such paths as

  • "/node/add/company"
  • "/node/add/companyblablabla"

is it bug or my mistake ?


Viewing all articles
Browse latest Browse all 294794

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>