Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I'd like to add some classes to local task items, not there are only "active" class available which is pretty not flexible, I'd like to have "first" on first item and "last" on last item.

Tried theme_menu_local_tasks() and theme_menu_local_task(), both doesn't work. And this post is probably for Drupal 6 so it's not working either.

share|improve this question
add comment

2 Answers

You could use hook_menu_local_tasks_alter(). You can access all local tasks through the first parameter$data and you can add more class names to the option array localized_options of each tab.

function YOURMODULE_menu_local_tasks_alter(&$data, $router_item, $root_path){
    if(isset($data['tabs'][0])){
        $tabs =  $data['tabs'][0];  
        $i = 1; 
        foreach($tabs['output'] as &$t){
            if($i == 1) $class = 'first';
            elseif($i = $tabs['count']) $class = 'last';
            if(isset($t['#link']['localized_options']['attributes'])){
                $attributes = $t['#link']['localized_options']['attributes'];
                $attributes['class'][] = $class;
            }else{
                $attributes = array(
                    'attributes' => array(
                        'class' => array($class)
                    )
                );
            }
            $t['#link']['localized_options'] = $attributes; 
            $i++;
        }
        $data['tabs'][0] = $tabs;
    }
}

If you don't want to loop through all local tasks for performance sake, you can directly update$data['tabs'][0]['output'][0] and $data['tabs'][0]['output'][$data['tabs'][0]['count']-1]. But you should check if the indexes exist, otherwise you will get Warning: Undefined index...

share|improve this answer
add comment

You may use the nth-child CSS 3 property if .active is not convinent:

p:nth-child(2) {
  background:#ff0000;
} 

Source is w3schools.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.