Created
November 6, 2012 11:17
-
-
Save opi/4024093 to your computer and use it in GitHub Desktop.
Add contextual link to block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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