You are here

colossal_menu.module in Colossal Menu 2.x

Same filename and directory in other branches
  1. 8 colossal_menu.module

Colossal Menu Hooks.

File

colossal_menu.module
View source
<?php

/**
 * @file
 * Colossal Menu Hooks.
 */
use Drupal\Core\Render\Element;
use Drupal\Core\Block\BlockPluginInterface;

/**
 * Implements hook_theme().
 */
function colossal_menu_theme() {
  return [
    'colossal_menu' => [
      'variables' => [
        'menu_name' => NULL,
        'items' => [],
        'attributes' => [],
      ],
    ],
    'colossal_menu_link' => [
      'render element' => 'elements',
    ],
  ];
}

/**
 * Prepares variables for Link templates.
 *
 * @param array $variables
 *   An associative array containing:
 *   - elements: An associative array containing the user information and any
 *   - attributes: HTML attributes for the containing element.
 */
function template_preprocess_colossal_menu_link(array &$variables) {

  // Helpful $content variable for templates.
  foreach (Element::children($variables['elements']) as $key) {
    $variables['content'][$key] = $variables['elements'][$key];
  }
}

/**
 * Implements hook_block_view_BASE_BLOCK_ID_alter().
 */
function colossal_menu_block_view_colossal_menu_block_alter(array &$build, BlockPluginInterface $block) {
  $build['#contextual_links']['colossal_menu'] = [
    'route_parameters' => [
      'colossal_menu' => $block
        ->getDerivativeId(),
    ],
  ];
}