Skip to content

Instantly share code, notes, and snippets.

@opi
Created November 6, 2012 11:17
Show Gist options
  • Save opi/4024093 to your computer and use it in GitHub Desktop.
Save opi/4024093 to your computer and use it in GitHub Desktop.
Add contextual link to block
<?php
// See http://dominiquedecooman.com/blog/drupal-7-tip-add-contextual-links-anything
// See http://drupal.org/node/1089922
// hook_menu
// Menu item must have 'context' set to MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE
function mymodule_menu() {
return array(
'admin/mymodule/myblock' => array(
'title' => "My Block",
'page callback' => 'mymodule_myblock_callback',
'type' => MENU_LOCAL_TASK,
'weight' => 15,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE, // This is the important part !!
'access arguments' => array('administer mymodule')
),
);
}
// Block view callback
// Contextual links must be in $block['content']['#contextual_links']
function mymodule_block_myblock() {
return array(
'subject' => t("My Block"),
'content' => array(
'#markup' => "My block content",
'#contextual_links' => array(
'mymodule' => array(
'admin/mymodule/myblock',
array('')
),
),
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment