I created a context with "sitewide context" condition always active. On reaction I added "menu" and selected an item from the main menu. I also added a block to the main content region to verify the context is really active.

When visiting any page the block is shown but my main menu item is not active.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

idflood’s picture

It seems this is coming from a conflict with i18n. I'm not sure where the issue really is and by which module it must be handled.

Here is how to reproduce:
1. create a context with a menu reaction, with a sitewide context condition ( this should be working )
2. add i18n and variable ( dependency ) then enable "internationalization" and "Menu translation" modules
3. refresh, the menu is not set as active

idflood’s picture

Title: Menu reaction doesn't have any effect » i18n conflict - Menu reaction doesn't have any effect
luckystrikerin’s picture

subscribing

idflood’s picture

I investigated a bit this issue. The execute function in context_reaction_menu.inc is triggered and change the active trail as expected. In fact it seems the menu links are redefined in i18n_menu.module ( in i18n_menu_preprocess_page ). Adding a return a the top of this function fix the context issue.

Digging deeper into the issue it seems I've found a hackish way of fixing the issue. In the file i18n_menu.module, change the end of i18n_menu_navigation_links function like this

  if (module_exists("context")) {
    $context = context_get_plugin('reaction', 'menu');
    $links = $context->menu_set_active($links);
  }
  return $links;
}
...

I hope there is a better way to fix the issue, i18n module shouldn't have to worry about context and other modules. Here is a related issue in i18n about it #1139722: context conflict - Menu are recreated in i18n_menu_preprocess_page even if they were already defined

anthonyR’s picture

subscribe

wapnik’s picture

Both context and i18n_menu are changing menu items by implementing hook_preprocess_page(). So the problem is about the order of execution. Changing module weights doesn't help because context is altering the theme registry to always hook right after template_preprocess_page() (see context_theme_registry_alter()). Now which module's weight should be changed and how? I think this is a question which maintainers of both modules have to decide.

idflood’s picture

Maybe you can have a look at the patch i posted there http://drupal.org/node/1139722#comment-4494374 . It may be another way of fixing this.

I think i18n must be called after context since context can completely change the menu displayed. so the proposed patch alter the current variables instead of recreating them.

wapnik’s picture

Status: Active » Needs review
FileSize
980 bytes

In #1139722: context conflict - Menu are recreated in i18n_menu_preprocess_page even if they were already defined the maintainer of i18n suggested that a context patch would be more efficient, here is the first try.

hctom’s picture

Status: Needs review » Reviewed & tested by the community

This patch in #8 works like a charm and the problems are gone! THanx a lot for this fix!

Cheers

hctom

idflood’s picture

FileSize
884 bytes

hmm, I've tested the patch in #8 and it didn't work for me. I will test again later and see if it pass the test I've created in http://drupal.org/files/issues/context_conflict-1139722-6.patch

I've manually corrected the path in the patch proposed in #8 since it wasn't applying (was pointing to /modules/contrib/context/context.core.inc instead of just /context.core.inc. (following the procedure described in http://drupal.org/project/context/git-instructions )

febbraro’s picture

Status: Reviewed & tested by the community » Needs work

One of the problems with this is that context needs to preprocess the page early on, that is why it is splicing right into the preprocess stack immediately after template_preprocess_page, this patch however is now putting it after i18n_menu, which could be just about anywhere in the preprocess stack. This also does not handle the case where i18n_preprocess_page is not in the stack (if they change their implementation then this will stop working entirely)

hctom’s picture

Okay.. how about this approach?

/**
 * Implementation of hook_theme_registry_alter().
 */
function context_theme_registry_alter(&$theme_registry) {
  // Push theme_page() through a context_preprocess to provide
  // context-sensitive menus and variables. Ensure that
  // context_preprocess_page() comes immediately after
  // template_preprocess_page().
  $position = array_search('context_preprocess_page', $theme_registry['page']['preprocess functions']);
  if ($position !== FALSE) {
    unset($theme_registry['page']['preprocess functions'][$position]);
  }
  $position = array_search('template_preprocess_page', $theme_registry['page']['preprocess functions']);
  $position = $position ? $position + 1 : 2;
  array_splice($theme_registry['page']['preprocess functions'], $position, 0, 'context_preprocess_page');
  // New stuf ++++++++++++++++++++++++++++++++++++++++++
  if (module_exists('i18n_menu')) {
      $index_context = array_search('context_preprocess_page', $theme_registry['page']['preprocess functions'], TRUE);
      $index_i18n_menu = array_search('i18n_menu_preprocess_page', $theme_registry['page']['preprocess functions'], TRUE);
      if ($index_context !== FALSE && $index_i18n_menu !== FALSE && $index_context < $index_i18n_menu) {
        unset($theme_registry['page']['preprocess functions'][$index_i18n_menu]);
        array_splice($theme_registry['page']['preprocess functions'], $index_context, 1, array('i18n_menu_preprocess_page', 'context_preprocess_page'));
      }
    }
}

Cheers

hctom

hctom’s picture

Status: Needs work » Needs review
ANDiTKO’s picture

#12 Works perfectly. Apply it and clear your cache.

stmh’s picture

#12 works on my side, too.

serg.remote’s picture

Neither #10 nor #12 work for me (i18n-6.x-1.10, i18nmenu_node-6.x-1.2).
#4 works

leenyx’s picture

Serg.remote, this post if for D7.

I have the same problem for D6...I have applied the solutions here [http://drupal.org/node/586396] with no luck, any ideas?

Jason Dean’s picture

#12 works great for me :)

joostpluijmers’s picture

I took the liberty of creating a patch to hctom's solution in #12. I created it against the 7.x-3.x branch. I do hope this makes it to the 3.0 release!

nodestroy’s picture

Status: Needs review » Needs work

actually the changes from #12 are working. that means, the context action now does what it is supposed to do.
But, the i18n_menu functionality is kind of broken, there are german menu items on english pages and english menu items on german pages.

tcmug’s picture

I can confirm that the patch #12 causes all kind of weird shit to happen. So much so that I actually thought I'm losing my mind.

tcmug’s picture

It appears that this is caused by the following part (between >>> and <<<) in plugins/context_reaction_menu.inc:

  /**
   * If primary + secondary links are pointed at the same menu, provide
   * contextual trailing by default.
   */
  function execute(&$vars = NULL) {
    // THIS >>>
    if (variable_get('menu_main_links_source', 'main-menu') == variable_get('menu_secondary_links_source', 'user-menu')) {
     $vars['main_menu'] = theme_get_setting('toggle_main_menu') ? $this->menu_navigation_links(variable_get('menu_main_links_source', 'main-menu')) : $vars['main_menu'];
     $vars['secondary_menu'] = theme_get_setting('toggle_secondary_menu') ? $this->menu_navigation_links(variable_get('menu_secondary_links_source', 'secondary-links'), 1) : $vars['secondary_menu'];
    }
    // <<<

    $vars['main_menu'] = $this->menu_set_active($vars['main_menu']);
    $vars['secondary_menu'] = $this->menu_set_active($vars['secondary_menu']);
  }

  function get_active_paths() {
    $active_paths = array();
    foreach ($this->get_contexts() as $context) {
      if (isset($context->reactions[$this->plugin])) {
        $active_paths[] = $context->reactions[$this->plugin];
      }
    }
    return $active_paths;
  }

So, removing those lines leaves the i18n_menu translations intact and the menu works just fine (atleast in our setup).

Maybe that part just needs to be patched so that it does not reset the menu?

tcmug’s picture

Adding a patch for the above for quicker testing.

tcmug’s picture

Attached patch AND the #12 patch seems to get this thing working.

luco’s picture

@tcmug, thank you for your work but it just won't work with me.

I got the latest DEV branch, applied patches from #12 and #24 but it will only work for menu items in English, not in Portuguese.

if you need more details please let me know. thanks in advance.

cheers,
Luciano

tcmug’s picture

Luciano: I had a look at what other patches we run to the module and found this Fix breadcrumb not working properly with i18n - I'm no expert on how the menus work but worth trying?

Also another difference is that we're using the beta3 version along with menu_block 2.2 to display the menus.

luco’s picture

@tcmug thanks for the reply. I'll test these options as soon as possible, but right now I have to present a working, well - something - without so much as real content. go figure. :)

guy_schneerson’s picture

I used both #8 and #24 and it fixed my issue, however I think this issue should be split into two:

Issue 1
"Stop i18n_menu from overriding context menu reactions" for patch #8, This should be committed as it insures the context menu reaction isn't overridden by i18n_menu.

Issue 2
"Make context menu reaction use i18n_menu if it is enabled" for patch #24, this worked for me but as i18n_menu has a number of use cases this may need more testing and is a separate issue from #8

I would handle this by keeping this issue "i18n conflict - Menu reaction doesn't have any effect" for Issue 1 (patch #8) and creating an new one for Issue 2 (patch #24)

tekante’s picture

Status: Needs work » Fixed

Committed 8 and 24 together. Thanks for the bug report and to the various work on the patch(es).

http://drupalcode.org/project/context.git/commit/baacf1593ab42fd63193afa...

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

luco’s picture

I can confirm it works even without Menu Block. :) thank you guys!