Poor theming of action links on node pages
Adding an action link to a node page has proven interesting, in that it does not show up on a stripped-down theme (but it is present in the HTML). (Note: action link code from the Definitive Guide to Drupal 7.)
We are adding this to a view called 'awards' and node number 20.
<?php
/**
* Implements hook_menu_local_tasks_alter().
*
* @TODO Look at performance implications of checking this on every node/ page,
* and consider an access check before any other check.
*/
function feature_ax_menu_local_tasks_alter(&$data, $router_item, $root_path) {
// Add action link to 'node/add/award' on awards listing pages.
if ($root_path == 'awards' || ($root_path == 'node/%' && $router_item['href'] == 'node/20')) {
$item = menu_get_item('node/add/award');
if ($item['access']) {
$data['actions']['output'][] = array(
'#theme' => 'menu_local_action',
'#link' => $item,
);
}
}
}
?>
Outputs this:
<ul class="links clearfix">
<li>
<a href="internal:node/add/award">Award</a>
</li>
</ul>
No class at all.
We can override theme_menu_local_action.
Or i can provide an alternate theming function for these special action links.
we can also add to our $link's options array, which can add classes to the a tag.
http://api.drupal.org/api/drupal/includes--common.inc/function/l/7
Also perhaps we should add a redirect to the link while messing with it, so after creating the node people go back to the view page they felt that node should be on!
Ah, most themes including Seven and Bartik handle the theming by adding the class to the unordered list in page.tpl.php. Here's an example from Rubik:
./sites/all/themes/rubik/page.tpl.php:20: <ul class='action-links links clearfix'><?php print render($action_links) ?></ul>
Comments
Post new comment