You are here

function menu_block_theme_suggestions_block_alter in Menu Block 8

Implements hook_theme_suggestions_HOOK_alter().

Adds block__system_menu_block so menu blocks work the same as core's menu blocks.

File

./menu_block.module, line 45
Provides configurable blocks of menu links.

Code

function menu_block_theme_suggestions_block_alter(array &$suggestions, array $variables) {
  if ($suggestions[0] == 'block__menu_block') {
    if ($suggestions[1] == 'block__menu_block') {

      // Since this first suggestion is a dupe, replace it with the system
      // suggestion.
      $suggestions[0] = 'block__system_menu_block';
    }
    else {
      array_unshift($suggestions, 'block__system_menu_block');
    }

    // The suggestions added with menu_block_theme_suggestions_block() are added
    // after the machine name-based suggestion, but are less specific and should
    // come before it.
    if (!empty($variables['elements']['#id'])) {
      $machine_name_suggestion = 'block__' . $variables['elements']['#id'];
      $suggestions = array_diff($suggestions, [
        $machine_name_suggestion,
      ]);
      $suggestions[] = $machine_name_suggestion;
    }
  }
}