Today I had a task to add nodequeue manipulation contextual links to some view. First I found this blog post, which explains, how to make desired menu items contextual links ready. As Marcus states in his post, I first needed to alter nodequeue menu items:
function MYMODULE_menu_alter(&$items) { $items['admin/structure/nodequeue/%nodequeue/edit']['context'] = MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE; $items['admin/structure/nodequeue/%nodequeue/view']['context'] = MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE; }
Nodequeue admin pages were now ready to be added to any contextual links on site. Since Marcus explains how to alter contextual links on blocks, I had to figure out how to do it with views. Solution turned out to be very simple. Contextual links are added to view in views-view.tpl.php, where $title_suffix is displayed. I just needed to add nodequeue contextual links to that variable (which is a render array in fact).
function MYTHEME_preprocess_views_view(&$vars) { $vars['title_suffix']['contextual_links']['#contextual_links']['sn_fpmain_news'] = array( // 3 is queue id in my case; it could be any other page argument 'admin/structure/nodequeue', array(3) ); }
And here is the result:
Is there any better way to do this?