You are here

function ultimenu_block_view in Ultimenu 7

Implements hook_block_view().

File

./ultimenu.module, line 131
Build Ultimenu regions based on enabled menu and its available menu items.

Code

function ultimenu_block_view($delta = '') {
  $config = ultimenu_get_config($delta);

  // If no menu link was found, don't display the block.
  if (empty($config['menu_name'])) {
    return array();
  }
  static $already_added = FALSE;
  $path = drupal_get_path('module', 'ultimenu');
  if (!$already_added) {
    $already_added = TRUE;
    drupal_add_js($path . '/js/ultimenu.js');
    drupal_add_css($path . '/css/ultimenu.css');
  }
  if (!empty($config['skin'])) {
    drupal_add_css($config['skin']);
  }

  // Get the full, un-pruned tree.
  // @todo use menu_navigation_links() since we don't support sub-menus,
  // or use menu_build_tree() for future exploration.
  // @see toolbar_get_menu_tree().
  $tree = menu_tree_all_data($config['menu_name']);

  // And add the active trail data to the full tree.
  ultimenu_tree_add_active_path($tree);

  // Allow alteration of the tree and config before we begin operations on it.
  drupal_alter('ultimenu_tree', $tree, $config);

  // Localize the tree.
  if (module_exists('i18n_menu')) {
    $tree = i18n_menu_localize_tree($tree);
  }

  // Render the tree.
  $data = array();
  if (($content = ultimenu_tree_output($tree, $config)) !== NULL) {
    $data['subject'] = NULL;
    $data['content']['#content'] = $content;
    $data['content']['#theme'] = array(
      'ultimenu__' . str_replace('-', '_', $config['menu_name']),
      'ultimenu',
    );
    $data['content']['#config'] = $config;
    $data['content']['#delta'] = $config['menu_name'];
  }
  return $data;
}