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

 
Giới thiệu sách Drupal 7 - Multi-sites Drupal Book

Giới thiệu sách Drupal 7 - Multi-sites Drupal Book

It took me some days to actually get started on this and start writing. As some of you already know, Packt has given me the Drupal 7 - Multi-sites Configuration book to review. 

MarTechTalks #3: Slide tài liệu của các diễn giả

MarTechTalks #3: Slide tài liệu của các diễn giả

Tất cả chúng ta đều biết rằng, các trang web đang được truy cập nhiều nhất trên thế giới đều có một điểm chung. Facebook, Google, Yahoo, Youtube, CNN…

Apple Store chiều khách hàng đến mức độ nào?

Apple Store chiều khách hàng đến mức độ nào?

Apple vốn đã rất nổi tiếng với chất lượng sản phẩm, nhưng Apple còn có cách riêng của mình để chiều lòng các “thượng đế” của mình.

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

 

Diet con trung