Skip to content

Instantly share code, notes, and snippets.

@sodacrackers
Created September 8, 2015 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sodacrackers/7cae5e79549d97dddf60 to your computer and use it in GitHub Desktop.
Save sodacrackers/7cae5e79549d97dddf60 to your computer and use it in GitHub Desktop.
Drupal 7 - Primary tabs with Bootstrap dropdown and Font Awesome icons
// Snippet for template.php file
// Two Drupal hooks to move primary tabs into a dropdown and, to use
// fontawesome icons for Drupal's edit menue. Requires Bootstrap components and Fontawesome CSS.
// Better than a module.
function THEME_menu_local_tasks(&$variables)
{
$output = '<div class="btn-group pull-right sphsc-tab-tasks">'
. '<button class="btn btn-info btn-lg dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
. t('Actions') . '<span class="caret"></span></button>'
. '<ul class="dropdown-menu fa-ul">';
if (!empty($variables['primary'])) {
$variables['primary']['#prefix'] = '<li><a><em>' . t('Primary tabs') . '</em></a></li>';
$output .= drupal_render($variables['primary']);
}
if (!empty($variables['secondary'])) {
$variables['secondary']['#prefix'] = '<li role="separator" class="divider"></li>'
. '<li><a><em>' . t('Secondary tabs') . '</em></a></li>';
$output .= drupal_render($variables['secondary']);
}
return $output . '</ul>';
}
function THEME_menu_local_task($variables)
{
$link = $variables['element']['#link'];
$link_text = $link['title'];
$icon = '';
$icon_icons = array(
'view' => 'fa-eye',
'edit' => 'fa-pencil',
'delete' => 'fa-trash-o',
'settings' => '', //'fa-cog',
'devel' => '', //'fa-cog',
'config' => '', //'fa-cog',
'grant' => '', //'fa-user-plus',
'revisions' => '', //'fa-list',
);
foreach($icon_icons as $key => $val) {
if(stripos($link_text, $key) !== false) {
$link_text = '<i class="fa fa-li '. $val .'"></i> ' . $link_text;
$link['localized_options'] += array('html' => true);
}
}
if (!empty($variables['element']['#active'])) {
$active = '<span class="element-invisible">' . t('(active tab)') . '</span>';
if (empty($link['localized_options']['html'])) {
$link['title'] = check_plain($link['title']);
}
$link['localized_options']['html'] = TRUE;
$link_text = t('!local-task-title!active', array(
'!local-task-title' => $link['title'],
'!active' => $active
));
}
return '<li' . (!empty($variables['element']['#active']) ? ' class="active"' : '') . '>'
. l($link_text, $link['href'], $link['localized_options']) . "</li>\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment