Quantcast
Channel: Recent posts across whole site
Viewing all articles
Browse latest Browse all 49206

DBUG meeting question follow-up: tabs for anon users

$
0
0

I asked a question at last night's DBUG meeting about using local menu task-style tabs for navigation links on a subset of pages in D7. In particular, I'd found a way to get new tabs appearing for logged-in users, but they were nowhere to be found for anonymous visitors:

<?php
function nga_helpers_menu_local_tasks_alter(&$data, $router_item, $root_path) {
 
$path = explode('/',drupal_get_path_alias());
  if(
$path[0] == 'public') {
   
$data['tabs'][0]['output'][] = array(
     
'#theme' => 'menu_local_task',
     
'#link' => array(
 
'title' => t('Example tab'),
  
'href' => 'public/careers',
      ),    );  } }
?>

I did some debugging after the meeting and found that the #link entries in the $tabs variable passed into the page template contained 'access_callback' keys, but trying to replicate them with something like 'access_callback' => TRUE in the above array didn't do anything. It's not documented anywhere I could find.

So I took a different approach and just put this into the theme template.php file, though it obviously needs more work to make it dynamic.

<?php
function nga_preprocess_page(&$variables, $hook) {
   
$path = explode('/',drupal_get_path_alias());
    if(
$path[0] == 'public' && $path[1] == 'careers')
   
$variables['tabs']['#primary'][] = array(
       
'#theme' => 'menu_local_task',
       
'#link' => array(
           
'href' => 'testing',
           
'title' => 'Preprocessed',
        ), ); }
?>

Does anyone have a simpler approach to this? Or is preprocess the best place to put it in the first place? I think hook_menu_local_tasks_alter is neat, but it's limited in utility if it only works to add logged-in tabs.


Viewing all articles
Browse latest Browse all 49206

Trending Articles