Skip to content

Instantly share code, notes, and snippets.

@oskarcalvo
Last active March 20, 2018 14:01
Show Gist options
  • Save oskarcalvo/b0679bf773ed15e1d29a9daf892298fc to your computer and use it in GitHub Desktop.
Save oskarcalvo/b0679bf773ed15e1d29a9daf892298fc to your computer and use it in GitHub Desktop.
menu_icon.php
<?php
/**
* {@inheritdoc}
*
* @see hook_preprocess_menu()
*/
function module/theme_preprocess_menu(&$variables) {
if($variables['menu_name'] == '$menu_name' ) {
foreach ($variables['items'] as $key => &$item) {
$menu_link = $item['original_link'];
$options = $menu_link->getOptions();
if (isset($options['attributes']['data-icon'])) {
$variables['items'][$key]['title'] = Markup::create('<i class="'. $options['attributes']['data-icon'] .'"></i><span>' .$item['title'] .'</span>');
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment