You are here

function menu_block_theme_suggestions_block in Menu Block 8

Implements hook_theme_suggestions_HOOK() for "block".

File

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

Code

function menu_block_theme_suggestions_block(array $variables) {
  $suggestions = [];

  // Check if this is a menu_block block.
  if (isset($variables['elements']['#base_plugin_id']) && $variables['elements']['#base_plugin_id'] == 'menu_block') {
    $menu_name = strtr($variables['elements']['#derivative_plugin_id'], '-', '_');
    $config = isset($variables['elements']['#configuration']) ? $variables['elements']['#configuration'] : [];

    // Context module (and perhaps others?) adds 'region' into the config.
    if (!empty($config['region'])) {
      $suggestions[] = 'block__menu_block__region_' . $config['region'];
      $suggestions[] = 'block__menu_block__' . $menu_name . '__region_' . $config['region'];
    }

    // Add our custom theme suggestion.
    if (!empty($config['suggestion']) && $config['suggestion'] !== $menu_name) {
      $suggestions[] = 'block__menu_block__' . $config['suggestion'];
    }

    // Context module adds block 'uuid' into the config.
    if (!empty($config['uuid'])) {
      $suggestions[] = 'block__menu_block__' . strtr($config['uuid'], '-', '_');
    }
  }
  return $suggestions;
}