I have following menu defined with access callback function. As You can see this is a hack so I can use REST via GET ( normally Services do not offer this ).

All my endpoints are defined /rest/api/[endpoint] this is a /config one:

function MYMODULE_menu() {
    $menus['rest/api/config'] = array(
        'title' => 'Configuration',
        'page callback' => 'MYMODULE_config',
        'access callback' => 'MYMODULE_access_callback_basic_auth',
        'type' => MENU_CALLBACK,
    return $menus;

The issue is that the MYMODULE_access_callback_basic_auth is called 5-times for every request.

Can You help me why this happens ?

1 Answer 1


Drupal forms are clever enough to know whether or not they've been submitted in the current page call and can react accordingly. Your best bet would be to move your code logic to inside the form function, where I think you can check for $form_state['#submitted'] to decide whether this code runs or not.

Alternatively you could check for the existence of $_POST variables in the MYMODULE_menu() function.

Check and read it out $form_state['cache'] = true; from here.

Hope that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.