User login

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>
Searched words: 
drupal link localized_options contextual administration help

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.