You are here

function template_preprocess_tb_megamenu_block in The Better Mega Menu 7

Same name and namespace in other branches
  1. 8 tb_megamenu.module \template_preprocess_tb_megamenu_block()
  2. 2.x tb_megamenu.module \template_preprocess_tb_megamenu_block()
1 string reference to 'template_preprocess_tb_megamenu_block'
tb_megamenu_theme in ./tb_megamenu.module
Implements hook_theme().

File

./tb_megamenu.themes.inc, line 313

Code

function template_preprocess_tb_megamenu_block(&$vars) {
  $block = tb_megamenu_load_block($vars['block_key']);
  if ($block) {
    $module = $block->module;
    $delta = $block->delta;
    $block_content = module_invoke($module, 'block_view', $delta);
    if (empty($block_content) && $vars['section'] == 'backend') {

      // Using description to show instead content.
      $blocks_info = module_invoke($module, 'block_info');
      $vars['content'] = $blocks_info[$delta]['info'];
    }
    elseif ($block_content) {
      $block->subject = '';
      $is_enabled_i18n_block = isset($block->i18n_mode) && $block->i18n_mode;

      // Translate content in block. And content must be a string.
      if ($is_enabled_i18n_block && !is_array($block_content['content'])) {
        $block->content =& $block_content['content'];
        $block->content = i18n_string_text("blocks:{$block->module}:{$block->delta}:body", $block->content);
      }

      // Check configuration for show block title;
      if (isset($vars['showblocktitle']) && $vars['showblocktitle']) {

        // If i18n_block is not enabled, so we will set title to subject.
        if (!$is_enabled_i18n_block) {
          $block->subject = $block->title ? $block->title : $block_content['subject'];
        }
        elseif (!empty($block->title) && $block->title != '<none>') {

          // Check plain here to allow module generated titles to keep any markup.
          $block->subject = $block->title;
          $block->subject = i18n_string_plain("blocks:{$block->module}:{$block->delta}:title", $block->subject);
        }
      }
      $vars['content'] = theme("block", array(
        'elements' => array(
          'content' => $block_content['content'],
          '#children' => is_array($block_content['content']) ? drupal_render($block_content['content']) : $block_content['content'],
          '#block' => $block,
        ),
      ));
    }
    else {
      $vars['content'] = NULL;
    }
    $vars['classes_array'][] = "tb-block";
    $vars['classes_array'][] = "tb-megamenu-block";
    $vars['attributes_array']['data-type'] = "block";
    $vars['attributes_array']['data-block'] = $vars['block_key'];
  }
  else {
    $vars['content'] = NULL;
  }
}