The main content block has no contextual links. I believe this is related to _block_get_renderable_array but I'm not really sure. I'm using Custom Contextual Links module to add contextual links to blocks, but of course it doesn't work with system-main (the main content block).

2 Answers 2


Contextual module (core) will preprocess the block renderable array and turn $block->content['#contextual_links'] into the block template $title_suffix using the contextual_links element type (see contextual_element_info). See contextual_preprocess for the implementation of this behavior.

While block module relies on _block_get_renderable_array for performance reasons, contextual links example module (from the examples package) shows an example of setting #contextual_links on hook_block_view.

As for CCL, it relies on hook_contextual_links_view_alter which will only alter or add links if there is already a #contextual_links element in the renderable array. The main content block doesn't get the default 'Configure block' contextual link (see _block_get_renderable_array), and therefore CCL doesn't affect it by default. Let's just add the default contextual link:

 * Implements hook_block_view_MODULE_DELTA_alter().
function MYMODULE_block_view_system_main_alter(&$data, $block) {
  if (user_access('access contextual links')) {
    $data['content']['#contextual_links']['block'] = array(
      array('system', 'main'),

This answer is not related to user's question. I wrote this in case others similar like me is looking for adding contextual link in hook_block_view.

Here is the contextual link example module mentioned by Barraponto regarding setting #contextual_links on hook_block_view.

http://api.drupalize.me/api/drupal/function/contextual_links_example_block_view/7 http://api.drupalize.me/api/drupal/function/contextual_links_example_menu/7

Another example will be the original drupal menu module.

// http://api.drupal.org/api/drupal/modules!menu!menu.module/function/menu_block_view/7
function menu_block_view($delta = '') {
  $menus = menu_get_menus(FALSE);
  $data['subject'] = check_plain($menus[$delta]);
  $data['content'] = menu_tree($delta);

  // Add contextual links for this block.
  if (!empty($data['content'])) {
    $data['content']['#contextual_links']['menu'] = array('admin/structure/menu/manage', array($delta));
  return $data;

// The contextual link above needs to work out with hook_menu as example show below.
// http://api.drupal.org/api/drupal/modules!menu!menu.module/function/menu_menu/7
function menu_menu() {

  $items['admin/structure/menu/manage/%menu'] = array(
    'title' => 'Customize menu', 
    'page callback' => 'drupal_get_form', 
    'page arguments' => array('menu_overview_form', 4), 
    'title callback' => 'menu_overview_title', 
    'title arguments' => array(4), 
    'access arguments' => array('administer menu'), 
    'file' => 'menu.admin.inc',
  $items['admin/structure/menu/manage/%menu/list'] = array(
    'title' => 'List links', 
    'weight' => -10, 


Hope it helps other who facing similar problem like me.

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.