Hello,

it is impossible for me to install the module, it throws :

TypeError: Argument 5 passed to Drupal\menu_position\Menu\MenuPositionActiveTrail::__construct() must be an instance of Drupal\Core\Entity\Query\QueryFactory, instance of Drupal\context\ContextManager given, called in /var/www/local.dev/my-website/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 286 in Drupal\menu_position\Menu\MenuPositionActiveTrail->__construct() (line 37 of modules/contrib/menu_position/src/Menu/MenuPositionActiveTrail.php).

Has someone experienced same issue ?
Many thanks for the advices.

CommentFileSizeAuthor
#3 menu-position-2944480-3.patch1.92 KBEtroid
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Clauce created an issue. See original summary.

Janez Zibelnik’s picture

Status: Active » Postponed

Context and Menu Position modules both have the same functionality of setting the active menu item on certain condition. In order to achieve that functionality, they both make changes to the core menu.active_trail service by adding different objects to the service constructor. The first in order is Context module that sets the context.manager in the active_trail service constructor and by the time Menu position does the same by trying to add entity.query service to index 4 of the constructor the active_trail is already set to expect a different kind of object on that index of the constructor. This explains the error message.

The solution depends on your use case:

1. If you use menu_position module to set the active menu item based on some conditions than the same functionality can be achieved by the context module itself, so you can remove the menu_position module.

2. If on the other hand, you use menu_position module to add the current page to the menu than I am afraid context module doesn't ship with this specific reaction. And using both modules at the same time isn't possible.

Etroid’s picture

While we prefer menu_position for setting active trail, we would still like to use all the other features that context has to offer. I suggest adding a condition around overwriting the menu.active_trail service to avoid collision when menu_position module is enabled:

  /**
   * {@inheritdoc}
   */
  public function alter(ContainerBuilder $container) {
    $modules = $container->getParameter('container.modules');
    // Only override the MenuActiveTrail module if the menu_position module
    // is not enabled.
    // @see https://www.drupal.org/project/context/issues/2944480
    if (!isset($modules['menu_position'])) {
      // Override the menu active trail with a new class.
      $definition = $container->getDefinition('menu.active_trail');
      $definition->setClass('Drupal\context\ContextMenuActiveTrail');
      $definition->addArgument($container->getDefinition('context.manager'));
    }
  }

Then we can also hook into the available context reactions and disable menu:

/**
 * Implements hook_context_condition_info_alter().
 *
 * Disables menu context reaction plugin if menu_position module is enabled.
 * @see https://www.drupal.org/project/context/issues/2944480
 *
 * @param $definitions
 */
function context_context_condition_info_alter(&$definitions) {
  $moduleHandler = \Drupal::service('module_handler');
  if ($moduleHandler->moduleExists('menu_position')) {
    unset($definitions['menu']);
  }
}
Etroid’s picture

Status: Postponed » Needs review
strozx’s picture

Status: Needs review » Reviewed & tested by the community

I have installed the menu_postion module and then the context module and the installation was successful. I have also checked for the disabled menu in the reactions section.

sense-design’s picture

#3 works good and fixes the error.

soothmidas’s picture

Not the same issue but related... if you are using the Menu Trail by Path module and install/enable Context the same core issue happens. The patch found in this thread fixed it for me: https://www.drupal.org/project/menu_trail_by_path/issues/2914746#comment...

criscom’s picture

#3 works for me. Thanks.

paulocs’s picture

This patch is specific for when Menu Position module is installed.
What we need is a general patch for when a module overrides the menu.active_trail, the context module will not break the site after it is installed.

I created a patch to a general approach in issue #3018331: Install fails if module Menu Trail by Path is installed.
Maybe you can review the patch there.

Cheers, Paulo.

paulocs’s picture

Status: Reviewed & tested by the community » Fixed

This issue was fixed in #3018331: Install fails if module Menu Trail by Path is installed.
It was created a general approach for it. When another module overrides the menu.active_trail, the menu reaction will not break the web site.

Thanks.

Status: Fixed » Closed (fixed)

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