You are here

function template_preprocess_mmenu in Mobile sliding menu 7.3

Same name and namespace in other branches
  1. 8 mmenu.module \template_preprocess_mmenu()
  2. 7 mmenu.module \template_preprocess_mmenu()
  3. 7.2 mmenu.module \template_preprocess_mmenu()

Processes variables for mmenu.tpl.php.

Most themes utilize their own copy of mmenu.tpl.php. The default is located inside "modules/mmenu/tpl/mmenu.tpl.php". Look in there for the full list of variables.

The $variables array contains the following arguments:

  • $mmenu
  • $id
  • $name
  • $blocks

See also

mmenu.tpl.php

File

./mmenu.module, line 1137
Primarily Drupal hooks and global API functions to manipulate mmenus.

Code

function template_preprocess_mmenu(&$variables) {
  $variables['mmenu'] = $variables['elements']['#mmenu'];
  $variables['id'] = $variables['elements']['#mmenu']['name'];
  $variables['name'] = $variables['elements']['#mmenu']['name'];
  $variables['blocks'] = array();
  static $mmenu_tree;
  foreach ($variables['mmenu']['blocks'] as $mmenu_block) {

    // Gets all menu blocks.
    $system_menus = menu_get_menus();
    $block = module_invoke($mmenu_block['module'], 'block_view', $mmenu_block['delta']);

    // When it is a menu block.
    if (isset($system_menus[$mmenu_block['delta']])) {

      // Builds the menu tree for rendering markup.
      $menu_parameters = isset($mmenu_block['menu_parameters']) ? $mmenu_block['menu_parameters'] : array();
      $menu_parameters['conditions']['hidden'] = 0;

      // Filters the menu items based on the current language.
      global $language;
      if (module_exists('i18n_menu')) {
        $menu_parameters['conditions']['language'] = array(
          'und',
          $language->language,
        );
      }
      if (!isset($mmenu_tree[$mmenu_block['delta']])) {
        $tree = menu_build_tree($mmenu_block['delta'], $menu_parameters);
        $mmenu_tree[$mmenu_block['delta']] = $tree;
      }
      else {
        $tree = $mmenu_tree[$mmenu_block['delta']];
      }
      $block['content'] = theme('mmenu_tree', array(
        'tree' => $tree,
        'reset' => TRUE,
        'depth' => 1,
      ));
    }
    else {
      $block_content = _block_render_blocks(array(
        block_load($mmenu_block['module'], $mmenu_block['delta']),
      ));

      // Sets title/subject to be empty because we don't need the title/subject
      // to be displayed in block.tpl.php.
      $key = $mmenu_block['module'] . '_' . $mmenu_block['delta'];
      if (isset($block_content[$key])) {
        $block_content[$key]->title = '';
        $block_content[$key]->subject = '';
        $block_build = _block_get_renderable_array($block_content);

        // Passes the mmenu to the block.tpl.php so you can access it
        // in the variable $elements['#mmenu'].
        $block_build[$mmenu_block['module'] . '_' . $mmenu_block['delta']]['#mmenu'] = $variables['elements']['#mmenu'];
        $block['content'] = render($block_build);
      }
      else {
        $block['content'] = '';
      }
    }

    // Uses the mmenu block title if it was defined.
    // Otherwise, uses default block subject.
    $subject = '';
    if ($mmenu_block['title'] == '<none>') {
      $subject = '';
    }
    elseif (!empty($mmenu_block['title'])) {
      $subject = $mmenu_block['title'];
    }
    elseif (isset($block['subject'])) {
      $subject = $block['subject'];
    }
    else {
      $subject = '';
    }
    $new_block['subject'] = $subject;

    // Renders block content.
    $new_block['content'] = render($block['content']);

    // Checks if the block is collapsed or expanded.
    $new_block['collapsed'] = isset($mmenu_block['collapsed']) ? $mmenu_block['collapsed'] : TRUE;

    // Checks if the block needs to wrap by
    // '<ul><li><span>xxxxxx</span></li></ul>'.
    $new_block['wrap'] = isset($mmenu_block['wrap']) ? $mmenu_block['wrap'] : FALSE;
    $new_block['module'] = $mmenu_block['module'];
    $new_block['delta'] = $mmenu_block['delta'];
    $new_block['icon_class'] = mmenu_get_icon_class('block', array(
      'module' => $mmenu_block['module'],
      'delta' => $mmenu_block['delta'],
    ));

    // Don't render if block content is empty.
    if (!empty($new_block['content'])) {
      $variables['blocks'][] = $new_block;
    }
  }

  // Template suggestions.
  $variables['theme_hook_suggestions'][] = 'mmenu__' . $variables['name'];

  // Adds CSS for particular mmenu.
  mmenu_add_css($variables['mmenu']);

  // Adds JS for particular mmenu.
  mmenu_add_js($variables['mmenu']);
}