2

We are using Drupal 7 with context. I have understood that in Drupal 6 the core block system is inefficient in terms of performance. According to this article http://treehouseagency.com/blog/neil-hastings/2010/10/14/context-everywhere in context module (Drupal 6 version) there is a setting to disable the core block system. But in Drupal 7 context module configuration I cannot find this setting.

How can I make sure the core block system doesn't take part in the showing of the blocks? Ideally I would like to block access to admin/structure/block (since I don't want anybody to set blocks via that interface) but allow to access to admin/structure/block/add (since I want to be able to create blocks but show them with context).

6
  • 3
    The block module is not required by core, just go to mysite.com/admin/modules and disable it if you don't want to use it in your site.
    – Clive
    Mar 9, 2012 at 11:11
  • Oh.. Too easy. By the way, is there a way to mark ur answer accepted when its' a comment?
    – jjei
    Mar 9, 2012 at 11:23
  • No that I'm aware of, I'll chuck it in an answer so you can accept :)
    – Clive
    Mar 9, 2012 at 11:31
  • Actually this is not a good way to do it, if u want to be able to create blocks but not use the core block system to render them.
    – jjei
    Apr 23, 2012 at 6:41
  • I also updated my original question.
    – jjei
    Apr 23, 2012 at 6:48

4 Answers 4

2

The block module is not required by core; just go to mysite.com/admin/modules and disable it, if you don't want to use it in your site.

EDIT to address your updated question. This code should do the trick. It will deny access directly to the blocks admin overview page, but will still allow access to the add block page.

function mymodule_menu_alter(&$items) {
  // Deny access to the blocks overview page.
  $items['admin/structure/block']['access callback'] = FALSE;

  // Explicitly allow access to the block add page
  $items['admin/structure/block/add']['access callback'] = 'user_access';
  $items['admin/structure/block/add']['access arguments'] = array('required permissions');
}
1
  • Thanks. I think admin/structure/blocks should be admin/structure/block (the first item). So the access to configure blocks is now prevented but does this prevent the core block system to do checks (should I show a block in this and this region when we are on a certain page etc.) and thus improve performance? I should probably first disable all the blocks using the core block system and then prevent the access to not enable them in the future from the core block system?
    – jjei
    Apr 24, 2012 at 9:09
1

Disabling the core block module would also disable all blocks. The context module also uses the block module to render blocks. You can see this by looking at the block reaction plugin in the context module.

There are a few methods. I recommend using use hook_menu_alter() to change the access arguments.

/**
 * Implements hook_menu_alter().
 */
function mymodule_menu_alter(&$items) {
  $items['admin/structure/block']['access arguments'] = array('my new powerful permission');
}

Then you can declare the permission in hook_permission if you want. But yo dont' have to. If you set the access arguments to a permission that doesn't exist, the page will render.

/**
 * Implements hook_permission().
 */
function mymodule_permission() {
  return array(
    'my new powerful permission' => array(
      'title' => t('Power Permission'),
      'description' => t('Very powerful stuff here'),
      'restrict access' => TRUE,
      'warning' => t('Do no give this to anyone'),
     ),
  ),
}
1
  • This would also restrict access to admin/structure/block/add, right? See the updated original question.
    – jjei
    Apr 23, 2012 at 6:55
0

You can disable block and enable bean. At present, this patch is required.

0

For the more advanced:

If you are defining a callback via hook_menu and wish to not display any blocks when that callback is ran, add the following to the top of your menu callback function.

<?php
  // Disable all blocks.
  $blocks = &drupal_static('block_list');
  $blocks = array();
?>

If some extra content is still getting through then using hook_page_alter can do the trick. In my case the admin_menu module was still showing up.

<?php
/**
 * Implements hook_page_alter()
 */
function mymodule_page_alter(&$page) {
  // Bail out if not on the my-awesome-page page and not on the
  // my-other-awesome-page page.
  // This code will vary quite a bit depending on your setup.
  $args = arg();
  if (   $args[0] !== 'my-awesome-page'
      && $args[0] !== 'my-other-awesome-page'
      ) {
    return;
  }

  // This code should stay the same.
  // Get page children.
  $children = element_children($page);
  // Kill all but content.
  foreach ($children as $value) {
    if ($value != 'content') {
      $page[$value] = '';
    }
  }
}
?>

Also noted that you might have to hide the footer with CSS due to the way drupal renders it. You can add this to your menu callback function as well.

<?php
  // Use CSS to hide the footer.
  drupal_add_css('#footer {display:none;}', array('type' => 'inline'));
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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