0

In my project I would like to add the following attributes to my "Login" main menu item:

data-toggle="modal" data-target="#login-modal" (Am using the Bootstrap theme)

I checked out the menu attribute module but it does not allow for these attributes.

Please is there a way?

3 Answers 3

4

You can use this HOOK_menu_link_alter and add new attribute from there.

https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_menu_link_alter/7

function MYMODULE_menu_link_alter(&$item) {
  if ($item['link_path'] == 'user/login') {
    $item['options']['attributes']['data-toggle'] = 'modal';
    $item['options']['attributes']['data-target'] = '#login-modal';
  }
}

Note : Make sure you clear cache and are checking this for anonymous user.

0

You can change the menu attribute module

If you are in drupal 7 Just install and enable menu attribute module module then go to module directory and edit menu_attributes.module to add following lines to menu_attributes_menu_attribute_info() function

Before return $info; line

//Added by ErangaJ 
$info['data-toggle'] = array(
'label' => t('Data toggle'),
'scope' => array(MENU_ATTRIBUTES_LINK, MENU_ATTRIBUTES_ITEM),
);
$info['data-target'] = array(
'label' => t('Data target'),
'scope' => array(MENU_ATTRIBUTES_LINK, MENU_ATTRIBUTES_ITEM),
);
1
  • You should never, ever change a contrib module code. Use alters to do this instead.
    – macjules
    Commented Jul 22, 2016 at 13:21
-1

You can use drupal module Bootstrap login modal

Adds a login and register link in the nav bar. Opens them in Bootstrap Modals.

This module is intended for use with the Bootstrap theme.

By default the login and register links are added to the navigation region, but they can be moved on the block admin page.

1
  • Hi makbuk and welcome. Please try to prevent link-only answers and include a relevant part of the answer in your post, optionally providing a link for further reference. It will give the OP a better idea of what to expect and your post will contain it's value in case the link would go down. Commented Jun 10, 2016 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.