The attached patch improves the display for navigation menus if also contextual links are enabled.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bengtan’s picture

Hi,

I'm sorry, but I think I misunderstand something.

Without this patch, both themes The Morning After and Aperture already work with Contextual Links ... at least, as far as I can tell.

Can you please tell me how the patch is supposed to improve things?

bengtan’s picture

jurgenhaas’s picture

Sorry, I should have explained the problem in more detail. What I've done is to inject a contextual links menu for primary links (= main menu) and that won't be displayed properly without the modifications in the css file.

There are two negative effects that I can explain and that are visible in the attachments to this post:

1) The widget on the right is not displayed properly, see "aperture original.jpg" and "aperture modified.jpg"

2) The dropdown from the widget widget on the right is not displayed properly, see "aperture original dropdown.jpg" and "aperture modified dropdown.jpg"

Please let me know if you need more details.

bengtan’s picture

Hi,

> What I've done is to inject a contextual links menu for primary links

Is this new contextual links menu part of Drupal core (because I don't see it in my test site(s))? If it is, I'm happy to include support for it in the theme(s). If not ... I'm a bit wary of supporting a one-off feature or something which may be obsoleted by Drupal core later on.

jurgenhaas’s picture

Yes, there is a simple hook in Drupal core that allows to attach contextual link menus to any kind of object on a page and the primary menu in particular is something that desperatly needs contextual links.

The proposed changes in the CSS are - even without the contactual link requirement - just a bit more specific to the elements in your great template. So there shouldn't be any harm in adding them into the theme.

bengtan’s picture

Hi,

For the patch for tma.theme ...

Without actually being to test like your setup ...

Are the 'ul#main-menu' declarations actually necessary?

I fail to see how ul#main-menu would be different from #main-menu in behaviour.

jurgenhaas’s picture

I guess you're right, #main-menu is just as good.

bengtan’s picture

Status: Active » Needs work

Hi,

I've just tested your patch and it changes the appearance of the navigation bar incorrectly. I think your patch is incomplete.

jurgenhaas’s picture

In which way, can you illustrate the effect?

bengtan’s picture

Hi,

The change of declaration from #navigation ul to #navigation ul.links results in the menu link text not being styled properly since #navigation ul.links no longer applies to it. As a result, the menu link text is a dark colour on a dark background.

Other than that, there is no other visible change ... but there is also nothing else in the patch which looks related to contextual links at all. The patch is very very small.

Perhaps you attached the wrong patch file?

jurgenhaas’s picture

Why should it not apply anymore? THe only ul that is available in #navigation does have the links class, so the selector "#navigation ul.links" should be perfectly right. Can't see what's wrong with it.

bengtan’s picture

Hi,

Interesting ...

When I tested and got the result in #10, I had reverted the ul#main-menu declarations to just #main-menu. It does have an effect.

If I test the patch without any modifications, it works.

Without the ul#main-menu declarations, it breaks.

So ... comment #10 is bogus and you have my apologies there.

However, the problem now has shifted ....

Stylistically, I don't like the ul#main-menu declarations. I feel that #main-menu should be sufficient. Can you please re-roll your patch to use #main-menu declarations?

jurgenhaas’s picture

FileSize
1.22 KB

No worries, CSS can be confusing some times. I have attached the shortened patch which is working fine here, unless I've overlooked something. Please let me know.

However, while looking at the code I was thinking that we could make the definitions for the a elements within #navigation and #main-menu still a bit more specific so that really only those get affected that should be.

bengtan’s picture

Hi,

Sorry, the patch from #13 isn't correct. The non-active anchor text within #navigation loses its white colour.

jurgenhaas’s picture

You're right, sorry I missed that. I've just checked the situation and found out that this is why we had ul#main-menu in the first patch. So I revert back to that first patch.

Hanno’s picture

Yes, there is a simple hook in Drupal core that allows to attach contextual link menus to any kind of object on a page and the primary menu in particular is something that desperatly needs contextual links.

Intersting, could you post the code you used to enable contextual links on the primary menu?

jurgenhaas’s picture

No problem, here you go:


/**
 * Implements hook_theme();
 */
function MYMODULE_theme($existing, $type, $theme, $path) {
  $items['links__system_main_menu'] = array(
    'variables' => array('menu' => 'main-menu', 'links' => NULL, 'attributes' => array('class' => array('links')), 'heading' => array()),
    'function' => 'MYMODULE_theme_menu',
  );
  $items['links__system_secondary_menu'] = array(
    'variables' => array('menu' => 'secondary-menu', 'links' => NULL, 'attributes' => array('class' => array('links')), 'heading' => array()),
    'function' => 'MYMODULE_theme_menu',
  );
  $items['menu_tree__main_menu'] = array(
    'render element' => 'tree',
    'function' => 'MYMODULE_theme_menu',
  );
  $items['menu_tree__secondary_menu'] = array(
    'render element' => 'tree',
    'function' => 'MYMODULE_theme_menu',
  );

  return $items;
}

function MYMODULE_theme_menu($variables) {
  if (isset($variables['tree'])) {
    $tree = $variables['tree'];
    foreach ($tree['#theme_wrappers'] as $theme_wrapper) {
      if (strpos($theme_wrapper, 'menu_tree__') !== FALSE) {
        $menu = str_replace('_', '-', substr($theme_wrapper, 11));
        $links = theme('menu_tree', $variables);
        break;
      }
    }
  }
  else {
    $menu = $variables['menu'];
    unset($variables['menu']);
    $links = theme('links', $variables);
  }
  if (empty($links)) {
    return '';
  }
  $build = array(
    'links' => array('#markup' => $links),
  );
  if (user_access('access contextual links')) {
    $build += array(
      'contextual_links' => array(
        '#type' => 'contextual_links',
        '#contextual_links' => array('menu' => array('admin/structure/menu/manage', array($menu)))
      ),
      '#prefix' => '<div class="contextual-links-region">',
      '#suffix' => '</div>',
    );
  }
  return drupal_render($build);
}