You are here

simple_mobile_menu.module in Simple Mobile Menu 8.2

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

File

simple_mobile_menu.module
View source
<?php

/**
 * @file
 * Contains simple_mobile_menu.module
 */
use Drupal\Core\Menu\MenuTreeParameters;

/**
 * Implements hook_help().
 * @return mixed
 */
function simple_mobile_menu_help($message) {
  $output = '';
  switch ($message) {
    case 'help.page.simple_mobile_menu':
      $output = '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('This is a Simple Mobile Menu. This will help you to create a Mobile Menu.') . '</p>';
      $output .= '<dl>';
      break;
  }
  return $output;
}

/**
 * Implements hook_page_bottom().
 */
function simple_mobile_menu_page_bottom(&$page) {

  // Don't apply this for admin routes.
  if (\Drupal::service('router.admin_context')
    ->isAdminRoute()) {
    return;
  }

  // Get the configuration.
  $config = \Drupal::config('simple_mobile_menu.settings');

  // Add the module's css file if the user does not want to disable it.
  if ($config
    ->get('include_css')) {
    $output['#attached']['library'][] = 'simple_mobile_menu/simple_mobile_menu.styling';
  }
}

/**
 * @param array $config
 *
 * @return mixed
 */
function simple_mobile_menu_build_tree(array $config) {
  $menu_tree = \Drupal::service('simple_mobile_menu.menu_tree');
  $parameters = new MenuTreeParameters();
  $tree = $menu_tree
    ->load($config[1], $parameters);
  $manipulators = [
    [
      'callable' => 'menu.default_tree_manipulators:checkAccess',
    ],
    [
      'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
    ],
  ];
  $tree = $menu_tree
    ->transform($tree, $manipulators);
  return $menu_tree
    ->build($tree);
}

/**
 * Implements hook_theme().
 *
 * @param array $existing 
 * @param string $type
 * @param string $theme
 * @param string $path
 *
 * @return array
 */
function simple_mobile_menu_theme($existing, $type, $theme, $path) {
  return [
    'simple_mobile_menu' => [
      'template' => 'simple-mobile-menu',
      'variables' => [
        'menu_output' => NULL,
      ],
    ],
    'menu__simple_mobile_menu' => [
      'base hook' => 'menu',
      'variables' => [
        'items' => [],
        'attributes' => [],
      ],
    ],
  ];
}