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

 
Alexa

Biện pháp tăng Alexa Rank

Thủ thuật tăng thứ hạng Alexa rất đa dạng. Nhưng về cơ bản Website của bạn cần thiết phải thực hiện những điều đơn giản sau để các cralwer của Alexa chú ý đến website của bạn hơn

Những checklist cần thiết để Going live Drupal

Những checklist Drupal cần thiết để Going live

So you're launching a new website or replacing an old one and want to make sure everything goes smoothly? This guide will give you a run-down of everything you can check to avoid common pitfalls!

Cha đẻ Facebook bị “chặt” 2 tỷ USD

Cha đẻ Facebook bị “chặt” 2 tỷ USD

Hóa đơn đóng thuế của Mark Zuckerberg trong năm 2012 có thể sẽ xác lập kỷ lục mới.

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

 

Diet con trung