I have a small module which creates and adds some custom settings for a block. Now I would like to control access to this blocks edit page. All users should be able to display the block, while changing the actual the configuration only should be available to certain users. Since I am not able to use hook_permission() I am not really sure how to best solve this so any help would be much appreciated.
Edit
I have tried this without any success:
function MYMODULE_block_info() { return array( 'MYBLOCK' => array( 'info' => t('MYBLOCK'), 'cache' => DRUPAL_CACHE_GLOBAL, ), ); } When I clear the cache and tries to go to the blocks edit page the url changes but nothing happens. It is like I am still standing on the block overview page?
function MYMODULE_permission() { return array( 'administer MYBLOCK' => array( 'title' => t('Administer MYBLOCK'), 'description' => t('Administer MYBLOCK settings.'), ), ); } function MYMODULE_menu_alter(&$items) { $items['admin/structure/block/manage/MYMODULE/MYBLOCK/configure']['access arguments'] = array('administer MYBLOCK'); } Edit
If I use user_access() in hook_block_configure() I almost achieve what I want. I don't know if this would be a valid way to solve this problem:
function MYMODULE_block_configure($delta = '') { $form = array(); if ($delta == 'MYBLOCK') { if (!user_access('administer MYBLOCK')) { drupal_set_message(t('You are not allowed to edit the @block block.', array('@block' => $delta)), WATCHDOG_WARNING); drupal_goto('admin/structure/block/manage'); drupal_exit(); } // Setup form for the block here. } return $form; }
admin/structure/block/manage/block/BLOCK_ID/configure. You could still use this path directly if you would like but just be aware that if the block were to be deleted and recreated from the frontend of the site, the BLOCK_ID would change.