Entity view (Content)

Using Contexture links in Drupal 6 & 7

By kwu
May. 25, 2012

One of the useful improvements in Drupal 7 is contextual links. It allows administrative users the ability to quickly perform tasks related to regions in the page. For example, when you hover your mouse over a block, links are displayed that allow you to click and go to the block configuration page without going through cumbersome Drupal administrative navigation. In Drupal 6, this module had been recently back ported from D7. Here are the steps to install it: Step 1: Download contextual link module from hereand place it under the modules folder. In general the folder would be sites/all/module/contextual. Step 2: Add extra variable to following template files under current theme folder. - node.tpl.php: $node_classes - views-view.tpl.php: $views_classes - block.tpl.php: $block_classes - page.tpl.php: $page_classes For example, the line with $node_classes inserted in node.tpl.php should read as:

class=" "

Step 3: Enable the module and assign 'access contextual links' permission to users. After that, the contextual links module should be working well for privileged users. In Drupal 6, contextual links module comes with some default links. You can also add your own task links to the contexture dropdown by implementing hook_contextual_block, hook_contextual_node, hook_contextual_view to make better user experiences. Here is an example that simply adding ‘Add New Page' to contextual dropdown in particular block.

/**
 *	Implement of hook_contextual_block
 */

function MODULE_NAME_contextual_block($block) {
  $links = array();
  $identifier = $block->module .'-'. $block->delta;
  switch ($identifier) {
    case MODULE_NAME-BLOCK_DELTA:
    $links[] = array (
      'weight' => 3,
      'title' => 'Add New Page',
      'href' => 'node/add/page',
      'access callback' => 'user _access',
      'access arguments' => array(‘create page content’)
    );
    break;
  }
  return $links;
}

The MODULE_NAME-BLOCK_DELTA should be replaced by corresponded values respecting block's module & delta key, such as the user login block provided by system module is 'system-0'. Next time I will show how to customize contextual links in Drupal 7. Thanks for reading.

Post Tags: