Dễ dàng thêm contextual link vào block trong Drupal 7

Dễ dàng thêm contextual link vào block trong Drupal 7

Contextual link is a nice addition made into Drupal 7 to favor usability. It offers, quick links to pages performing administrative operations. By default it is available for core block and node teaser view. But designed to be made extendable for other items too - Views, panels, and so.

Dễ dàng thêm contextual link vào block trong Drupal 7

Custom contextual link (aka ccl) module is the best choice for adding custom link items.

But I have faced some problems in ccl module while adding a custom contextual link for a block. I would like to share the problems and how I overcame the same.

ccl 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. 

In my case I have added the block on a panel, So the ccl modules doesn't affect my block. So I had to find a workaround. Problem explained in detail below,

I needed to create a contextual link for my follow block (from Follow module). The destination of the link is admin/config/services/follow. Then we have to create a menu for contextual link with the path in hook_menu()

/**
 * Implements hook_menu()
 */
function MY_MODULE_menu() {
  $items['admin/config/services/follow/configure'] = array(
    'title' => t('Edit follow'),
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'context' => MENU_CONTEXT_INLINE,
  );
return $items;
}

After that  we need to add the new contextual link in block's content using hook_block_view_MODULE_DELTA_alter()

/**
 * Implements hook_block_view_MODULE_DELTA_alter()
 */
function mymodule_block_view_follow_site_alter(&$data, $block) {
  $data['content']['#contextual_links']['follow'] = array(
    'admin/config/services/follow', array('follow', 'site'),
  );
}

Hooray! I got a new contextual link on my follow block. The same trick would work for other cases too. For example to add a contextual link to main menu.

>> Cấu hình Drupal settings file một cách chính xác

Bạn thấy bài viết này như thế nào?: 
No votes yet
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Symantec Connect - Social Business Software powered by Drupal

Symantec Connect là 1 Social Business Software phát triển bằng Drupal

Symantec Connect is an enterprise class, community-driven, social business support and information portal for Symantec products, offering users of Symantec’s deep catalog of applications

Tìm hiểu về mô hình kinh doanh của Amazon.com

Tìm hiểu về mô hình kinh doanh của Amazon.com

Khi biết tốc độ phát triển của Internet là 2300%/năm vào những năm đầu thập kỷ 90, mặc dù không có kinh nghiệm về bán hàng cũng như không nhiều hiểu biết về Internet nhưng Jeff Bezos –

So sánh Social Business Platforms: Part 3 - Drupal Commons

So sánh Social Business Platforms: Part 3 - Drupal Commons

In our first two posts we reviewed two of the most popular platforms for social business portals, Jive and Sharepoint.

Công ty diệt chuột T&C

 

Diet con trung