I really like the Commerce Kickstart's functionality but I would like to use a custom theme based on the bootstrap framework. When I enable the bootstrap theme the admin menu stops working properly. Can I use bootstrap with commerce kickstart and keeps its core functionality?

Comments

jonloh’s picture

I've found out the issue. It seems Bootstrap's theme/menu/menu-link.func.php is overriding the menu link theme with its own implementation, and it seems to be affecting the Commerce Kickstart Admin Menu which relies on the Management menu links because it's not rendering the children menu links.

The file attached is the patch file for Bootstrap actually. I'm not sure if this is the right way to fix, but it seems to work for now...

Hoping for a better solution by the Bootstrap project authors ;)

jonloh’s picture

Status: Active » Needs review
hmartens’s picture

I think you should check your admin menu if it works now because Admin Menu recently updated and since then my Admin menu has been working properly with Bootstrap.

I recently built a commmerce website using Commerce Kickstart and Bootstrap and it works perfect. I didn't run into anything funny.

ITWest-jg’s picture

PATCH WORKS FOR ME!!

Thank you so much! This has been bugging the team for a long time :)

This is on a clean install of commerce with bootstrap theme

lsolesen’s picture

Am I right that this patch is for Bootstrap? and that this issue is actually with bootstrap and not with CK?

hmartens’s picture

I would like to know whether just updating Admin Menu fixed their problem because on all my Bootstrap sites I only had to update Admin Menu to the latest version and everything is working perfect.

bonked’s picture

Better than patching Bootstrap 3 - you can add the following to your bootstrap sub-theme's template.php file.

function YOUR-BOOTSTRAP-3-SUBTHEME_menu_link(array $variables) {
  $element = $variables['element'];
  $sub_menu = '';

  if ($element['#below']) {
    // Prevent dropdown functions from being added to management menu so it
    // does not affect the navbar module.
    if (($element['#original_link']['menu_name'] == 'management') && (module_exists('navbar') || module_exists('commerce_kickstart_menus'))) {
      $sub_menu = drupal_render($element['#below']);
    }
    elseif ((!empty($element['#original_link']['depth'])) && ($element['#original_link']['depth'] == 1)) {
      // Add our own wrapper.
      unset($element['#below']['#theme_wrappers']);
      $sub_menu = '<ul class="dropdown-menu">' . drupal_render($element['#below']) . '</ul>';
      // Generate as standard dropdown.
      $element['#title'] .= ' <span class="caret"></span>';
      $element['#attributes']['class'][] = 'dropdown';
      $element['#localized_options']['html'] = TRUE;

      // Set dropdown trigger element to # to prevent inadvertant page loading
      // when a submenu link is clicked.
      $element['#localized_options']['attributes']['data-target'] = '#';
      $element['#localized_options']['attributes']['class'][] = 'dropdown-toggle';
      $element['#localized_options']['attributes']['data-toggle'] = 'dropdown';
    }
  }
  // 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";
}
dxx’s picture

Thanks bonked!

mglaman’s picture

Project: Commerce Kickstart » Bootstrap
Version: 7.x-2.19 » 7.x-3.x-dev

Moving this from Commerce Kickstart queue to Bootstrap, as it looks like patch is for the theme's logic check on theming menu links.

markhalliwell’s picture

Title: Can I use bootstrap theme with kickstart? » Management sub-menus not rendered properly using Commerce Kickstart
Component: Miscellaneous » Code
Category: Support request » Bug report
Priority: Normal » Minor
Status: Needs review » Needs work
Related issues: +#1893532: [bootstrap][policy][7.x-3.x] Navigation/Menus

De-escalating priority since this can easily be mitigated by implementing a sub-theme override as suggested in #7.

I was almost tempted to close this a duplicate of the related issue I'm attaching here, however this is an issue that only creeps up when using a specific module.

FWIW, I'm not really a fan of using module_exists() in code like this that is executed quite frequently (performance reasons).

Despite the fact that we're already doing this for navbar; I'm going to leave this open so a more elegant solution can be determined than the current makeshift hacks implemented here.

Comevents-web6’s picture

It worked with your code bonked! Thanks

sachchidanand’s picture

Commerce Kick start management(admin menu link) are not working with bootstrap theme. Sub links are not displaying with bootstrap theme.It works for other than bootstrap theme. FYR http://screencast.com/t/gJRreNz3W1
Kindly suggest

Thanks,
sachchidanand

markhalliwell’s picture

@sachchidanand, the current "solution" is either #1 or #7.

catFighter’s picture

#7 work very good. You need to only add this to the main theme. Also working when you log on the admin area where is different theme (admin theme). In this way you can still update parent theme bootstrap without lose this fix!!!

markhalliwell’s picture

Status: Needs work » Closed (won't fix)

I agree that #7 is the more likely solution for this. Not every site will have commerce and I would like to avoid additional module_exists calls in this.

fahadurrehman’s picture

I put the code from #7 in my subtheme's template.php file changed the YOUR-BOOTSTRAP-3-SUBTHEME to my theme name but the menu gets more weird and dropdown still not worked.

legrandkay’s picture

I tested this with bootstrap 7.x-3.14
This is similar to #7. Paste this into your sub-themes template.php file.

<?php
function YOUR-BOOTSTRAP-3-SUBTHEME_menu_link(array $variables) {
  $element = $variables['element'];
  $sub_menu = '';

  $options = !empty($element['#localized_options']) ? $element['#localized_options'] : array();

  // Check plain title if "html" is not set, otherwise, filter for XSS attacks.
  $title = empty($options['html']) ? check_plain($element['#title']) : filter_xss_admin($element['#title']);

  // Ensure "html" is now enabled so l() doesn't double encode. This is now
  // safe to do since both check_plain() and filter_xss_admin() encode HTML
  // entities. See: https://www.drupal.org/node/2854978
  $options['html'] = TRUE;

  $href = $element['#href'];
  $attributes = !empty($element['#attributes']) ? $element['#attributes'] : array();

  if ($element['#below']) {
    // Prevent dropdown functions from being added to management menu so it
    // does not affect the navbar module.
    if (($element['#original_link']['menu_name'] == 'management') && (module_exists('navbar') || module_exists('commerce_kickstart_menus'))) {
      $sub_menu = drupal_render($element['#below']);
    }
    elseif ((!empty($element['#original_link']['depth'])) && ($element['#original_link']['depth'] == 1)) {
      // Add our own wrapper.
      unset($element['#below']['#theme_wrappers']);
      $sub_menu = '<ul class="dropdown-menu">' . drupal_render($element['#below']) . '</ul>';

      // Generate as standard dropdown.
      $title .= ' <span class="caret"></span>';
      $attributes['class'][] = 'dropdown';

      // Set dropdown trigger element to # to prevent inadvertant page loading
      // when a submenu link is clicked.
      $options['attributes']['data-target'] = '#';
      $options['attributes']['class'][] = 'dropdown-toggle';
      $options['attributes']['data-toggle'] = 'dropdown';
    }
  }

  return '<li' . drupal_attributes($attributes) . '>' . l($title, $href, $options) . $sub_menu . "</li>\n";
}
?>