You are here

entity_submenu_block.module in Entity Submenu Block 8

Functions to support theming Entity Submenu Blocks.

File

entity_submenu_block.module
View source
<?php

/**
 * @file
 * Functions to support theming Entity Submenu Blocks.
 */

/**
 * Implements hook_theme().
 */
function entity_submenu_block_theme($existing, $type, $theme, $path) {
  return [
    'entity_submenu' => [
      'variables' => [
        'menu_name' => NULL,
        'menu_items' => NULL,
      ],
    ],
    'entity_submenu_item' => [
      'variables' => [
        'url' => NULL,
        'title' => NULL,
      ],
    ],
  ];
}

/**
 * Implements hook_theme_suggestions_HOOK() for "entity_submenu".
 */
function entity_submenu_block_theme_suggestions_entity_submenu(array $variables) {
  $suggestions = [];
  if (isset($variables['menu_name'])) {
    $menu_name = strtr($variables['menu_name'], '-', '_');
    $suggestions[] = 'entity_submenu__' . $menu_name;
  }
  return $suggestions;
}

/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function entity_submenu_block_theme_suggestions_block_alter(array &$suggestions, array $variables) {
  if ($suggestions[0] == 'block__entity_submenu_block') {
    if ($suggestions[1] == 'block__entity_submenu_block') {

      // Since the first suggestion is a dupe, remove it.
      array_shift($suggestions);
    }
  }
}