Hi,

I was experimenting with Menu Multilingual module and the filtering capabilities this module provides seem to fulfill exactly what I need on my multilingual site.

I was also planning to use the Responsive and off-canvas menu module. This module allows you to choose which Drupal Menu is rendered in the blocks provided by it.

So basically what I would ultimately like to achieve is this:

  • I have the standard Drupal Main Menu where I have all menu links
  • I use the Responsive and off-canvas menu module to render the menu links. This provides two blocks.
  • In the blocks provided by Responsive and off-canvas menu, I would like to filter the menu links based on the language with this module.

Currently, the multilingual options provided by this module only appear in the block configuration of the standard Drupal 8 menu blocks.

Feature request: support the filtering also for the blocks provided by the Responsive and off-canvas menu module.

Cheers,
Markus

Comments

masipila created an issue. See original summary.

masipila’s picture

Okay I was digging this a bit myself and I think I'm quite close.

The Responsive and off-canvas menu module provides two blocks. I tried to get the multilingual options provided by this module working with the first one.

The first block has plugin id 'responsive_menu_toggle'. The class for this is Drupal\responsive_menu\Plugin\Block\Toggle.

What I tried to do is that I created a class that extends the Toggle just like we have classes that extend SystemMenuBlock and MenuBlock:

<?php

namespace Drupal\menu_multilingual\Plugin\Block;

use Drupal\responsive_menu\Plugin\Block\Toggle;

class ToggleMultilingual extends Toggle {

  use MenuMultilingualBlockTrait;

}

To get this to appear on the block configuration form, I tried to modify the hook as follows:

/**
 * Implements hook_block_alter().
 */
function menu_multilingual_block_alter(&$definitions) {
  foreach ($definitions as $key => $definition) {
    if (substr($key, 0, 18) == 'system_menu_block:') {
      $definitions[$key]['class'] = 'Drupal\menu_multilingual\Plugin\Block\SystemMenuBlockMultilingual';
    }
    if (substr($key, 0, 11) == 'menu_block:') {
      $definitions[$key]['class'] = 'Drupal\menu_multilingual\Plugin\Block\MenuBlockMultilingual';
    }
    if ($key == 'responsive_menu_toggle') {
      $definitions[$key]['class'] = 'Drupal\menu_multilingual\Plugin\Block\ToggleMultilingual';
    }
  }
}

But for some reason I'm still not able to see the multilingual options on the block configuration form... I know I'm really close but would appreciate if you could push me a over the line...

Cheers,
Markus

vlad.dancer’s picture

Hi, Markus. I think you should also implement this hook hook_block_view_BASE_BLOCK_ID_alter like:

function menu_multilingual_block_view_responsive_menu_toggle_alter(array &$build) {
  Helpers::setBlockProcessing($build);
}
masipila’s picture

Thanks! I'll give it a try during the weekend and provide a patch for the whole thing if I get it working!

Markus

masipila’s picture

Hi,

I found out the reason why the fields do not appear in the block configuration form is this.

trait MenuMultilingualBlockTrait {

  /**
   * {@inheritdoc}
   */
  public function blockForm($form, FormStateInterface $form_state) {
    $config = $this->configuration;

    $form = parent::blockForm($form, $form_state);

    $disabled_labels  = !Helpers::checkEntityType('menu_link_content');
    $disabled_content = !Helpers::checkEntityType('node');

    $multilingual = [
      '#type'        => 'details',
      '#open'        => TRUE,
      '#title'       => t('Multilingual options'),
      '#description' => t('Control visibility of menu items depending on their available translations.<br><strong>Notice:</strong> menu items with untranslated parents will also not be displayed.'),
      '#process' => [[get_class(), 'processMenuLevelParents']],
    ];

The $multilingual form element has the #process callback.

The configuration fields are visible on Drupal\menu_multilingual\Plugin\Block\SystemMenuBlockMultilingual. This class extends Drupal\system\Plugin\Block\SystemMenuBlock, which has the processMenuLevelParents method which is used in the callback.

Now, when I look at Drupal\responsive_menu\Plugin\Block\Toggle, it extends Drupal\Core\Block\BlockBase which does not have the processMenuLevelParents method.

I'll continue hacking this but wanted to drop a note here on what's going on.

Markus

masipila’s picture

I opened #2953911: Integrating with Menu Multilingual module to figure out if the block provided by responsive_menu could extend SystemMenuBlock instead of BlockBase.

masipila’s picture

Status: Active » Closed (won't fix)

It seems that the responsive_menu module can't be easily integrated with menu_multilingual because the blocks are not prepared as SystemMenuBlocks but directly as BlockBase. See the comment at https://www.drupal.org/project/responsive_menu/issues/2953911#comment-12...

For other's that might come up to this issue: the hooks provided by responsive_menu allowed me to achieve what I needed without using menu_multilingual. I documented the approach I used to the handbook of responsive_menu: https://www.drupal.org/node/2681651#multilingual-sites

Closing this issue as WONTFIX.

Cheers,
Markus

matsbla’s picture

Okay cool, nice to see you found a solution!