Skip to content

Instantly share code, notes, and snippets.

@waako
Created April 21, 2014 13:06
Show Gist options
  • Save waako/11142208 to your computer and use it in GitHub Desktop.
Save waako/11142208 to your computer and use it in GitHub Desktop.
<?php
/**
* @file
* menu-link.func.php
*/
/**
* Overrides theme_menu_link().
*/
function bootstrap_theme_menu_link(array $variables) {
kpr($variables);
$element = $variables['element'];
$sub_menu = '';
kpr($variables);
// On primary navigation menu, class 'active' is not set on active menu item.
// @see https://drupal.org/node/1896674
if (($element['#href'] == $_GET['q'] || ($element['#href'] == '<front>' && drupal_is_front_page())) && (empty($element['#localized_options']['language']))) {
$element['#attributes']['class'][] = 'active';
}
$output = l($element['#title'], $element['#href'], $element['#localized_options']);
return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}
function MYAWESOMETHEME_menu_link(array $variables) {
/**
* Implements theme_menu_link().
*
* This code adds an icon <I> tag for use with icon fonts when a menu item
* contains a CSS class that starts with "icon-". You may add CSS classes to
* your menu items through the Drupal admin UI with the menu_attributes contrib
* module.
*
* Originally written by lacliniquemtl.
* Refactored by jwilson3 > mroji28 > driesdelaey.
* @see http://drupal.org/node/1689728
*/
$element = $variables['element'];
$sub_menu = '';
// If there is a CSS class on the link that starts with "icon-", create
// additional HTML markup for the icon, and move that specific classname there.
// Exclusion List for settings eg http://fontawesome.io/examples/
$exclusion = array(
'fa-lg','fa-2x','fa-3x','fa-4x','fa-5x',
'fa-fw',
'fa-ul', 'fa-li',
'fa-border',
'fa-spin',
'fa-rotate-90', 'fa-rotate-180','fa-rotate-270','fa-flip-horizontal','fa-flip-vertical',
'fa-stack', 'fa-stack-1x', 'fa-stack-2x',
'fa-inverse'
);
if (isset($element['#original_link']['options']['attributes']['class'])) {
foreach ($element['#original_link']['options']['attributes']['class'] as $key => $class) {
if (substr($class, 0, 3) == 'fa-' && !in_array($class,$exclusion)) {
// We're injecting custom HTML into the link text, so if the original
// link text was not set to allow HTML (the usual case for menu items),
// we MUST do our own filtering of the original text with check_plain(),
// then specify that the link text has HTML content.
if (!isset($element['#original_link']['options']['html']) || empty($element['#original_link']['options']['html'])) {
$element['#title'] = check_plain($element['#title']);
$element['#localized_options']['html'] = TRUE;
}
// Add the default-FontAwesome-prefix so we don't need to add it manually in the menu attributes
$class = 'fa ' . $class;
// Create additional HTML markup for the link's icon element and wrap
// the link text in a SPAN element, to easily turn it on or off via CSS.
$element['#title'] = '<i class="' . $class . '"></i> <span>' . $element['#title'] . '</span>';
// Finally, remove the icon class from link options, so it is not printed twice.
unset($element['#localized_options']['attributes']['class'][$key]);
// kpr($element); // For debugging.
}
}
}
// Save our modifications, and call core theme_menu_link().
$variables['element'] = $element;
return theme_menu_link($variables);
}
function bartik_menu_link__menu_block__19(&$variables) {
// set options below
$options = array('component' => 'button_dropdowns', 'options' => array('split' => true, 'alignment' => 'left', 'direction' => 'down', 'vertical' => true));
// stop, and enjoy
if(module_exists('bootstrap_components')){
$pra_options = array();
if(isset($variables['element']['#localized_options']['bootstrap_components'])) $pra_options = $variables['element']['#localized_options']['bootstrap_components'];
$variables['element']['#localized_options']['bootstrap_components'] = $options + $pra_options;//wajib ada index bootstrap_components
return theme_bootstrap_components_menu_link($variables);
}
else return theme_menu_link($variables);
}
<?php
function OMEGASUBTHEME_menu_link(array $variables) {
global $user;
$element = $variables['element'];
$sub_menu = '';
if ($element['#below']) {
$sub_menu = drupal_render($element['#below']);
}
$title = '';
// Check if the user is logged in, that you are in the correct menu,
// and that you have the right menu item
if ($user->uid != 0 && $element['#theme'] == 'menu_link__user_menu' && $element['#title'] == t('My account')) {
$element['#title'] = $user->name;
// Add 'html' = TRUE to the link options
$element['#localized_options']['html'] = TRUE;
// Load the user picture file information; Unnecessary if you use theme_user_picture()
$fid = $user->picture;
$file = file_load($fid);
// I found it necessary to use theme_image_style() instead of theme_user_picture()
// because I didn't want any extra html, just the image.
$title = theme('image_style', array('style_name' => 'thumbnail', 'path' => $file->uri, 'alt' => $element['#title'], 'title' => $element['#title'])) . $element['#title'];
} else {
$title = $element['#title'];
}
$output = l($title, $element['#href'], $element['#localized_options']);
return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment