You are here

simple_mobile_menu.module in Simple Mobile Menu 8

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

File

simple_mobile_menu.module
View source
<?php

/**
 * @file
 * Contains simple_mobile_menu.module
 */
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Link;
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Url;

/**
 * Implements hook_help().
 */
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;
}
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 javascript behaviours.
  // $output['#attached']['library'][] = 'simple_mobile_menu/simple_mobile_menu.script';
  // 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();

  // print_r($config);
  $tree = $menu_tree
    ->load($config[1], $parameters);
  $manipulators = array(
    array(
      'callable' => 'menu.default_tree_manipulators:checkAccess',
    ),
    array(
      'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
    ),
  );
  $tree = $menu_tree
    ->transform($tree, $manipulators);
  return $menu_tree
    ->build($tree);
}

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