-2

I'm trying to check if a user has permission(registered by a module) before he adds/edits fields on a node type registered by the module.

The approach is to use hook_menu_alter and add an access callback.

The URL i am trying to add this to is

admin/structure/types/manage/applx-application/fields

Where 'applx-application' is the node type.

The problem is after the callback has been added via the hook, the page falls to admin/structure/types/ instead of admin/structure/types/manage/applx-application/fields

I'm not sure what i'm doing wrong. Oh and hook_menu_alter is called by hook_hook_info. If that is of any concern.

    <?php
/*
    Implements hook_menu_alter
*/
function applx_menu_alter(&$items){
    $items['admin/structure/types/manage/applx-application/fields']['access callback'] = 'applx_permission_check';
    $items['admin/structure/types/manage/applx-application/fields']['access arguments'] = array('field_management');
}

My only guess is that it falls back to structure/types because the system module's menu hook expects a wildcard in place of applx-application i suppose.

What is the right way to do this, if not this way?

-1

Digging a little bit more i found out that the right way to do this is to use

hook_field_access

  • May you expand a little your answer? Saying you found another hook to use doesn't help future users, which is what Stack Exchange aims to do. – kiamlaluno Feb 16 '16 at 4:15

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.