Menu block theme suggestion

Geschreven op 01 maart 2018 door Cor van Oostenbrugge

Theming Drupal 8 Menu blocks

This snippet enables you add your own theme suggestion for menu blocks.

/**
 * Implements hook_preprocess_block().
 */
function THEME_NAME_preprocess_block(&$variables) {
  $block_id = $variables['elements']['#id'];
  $block = Block::load($block_id);
  $variables['content']['#attributes']['region'] = $block->getRegion();
}

/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function THEME_NAME_theme_suggestions_menu_alter(array &$suggestions, array $variables) {
  if (isset($variables['attributes']['region'])) {
    $suggestions[] = 'menu__' . $variables['attributes']['region'];
  }
}

Reactie toevoegen

Plaats hier uw naam.