You are here

function template_preprocess_om_maximenu_submenu_links in OM Maximenu 8

Same name and namespace in other branches
  1. 6 inc/om_maximenu.render.inc \template_preprocess_om_maximenu_submenu_links()
  2. 7 inc/om_maximenu.render.inc \template_preprocess_om_maximenu_submenu_links()

Process variables for om_maximenu_submenu_links.tpl.php

File

inc/om_maximenu.render.inc, line 441
OM Maximenu Render

Code

function template_preprocess_om_maximenu_submenu_links(&$vars) {
  $disabled = $vars['disabled'];
  $content = $vars['content'];

  // user roles and permissions
  $vars['permission'] = om_maximenu_link_visible($vars['content']['roles']);

  // php on title
  if (isset($content['php_option']) && $content['php_option'] == 1) {
    ob_start();
    $content['link_title'] = eval($content['link_title']);

    //$output = ob_get_contents();
    ob_end_clean();
  }

  // span id
  $span_id = !empty($content['id']) ? ' id="' . om_string_name($content['id']) . '"' : '';

  // span title
  $span_title = !empty($content['description']) && $content['description_option'] == 'hover' ? 'title="' . check_plain($content['description']) . '"' : '';

  // link content
  $link_option = om_maximenu_link_option($content);

  // a link attributes
  $attributes = om_maximenu_link_attrib($content);

  // link is disabled when it's on its page
  $uri = trim($_SERVER['REQUEST_URI']);
  $qpath = $_GET['q'];
  $path_relative = base_path() . $content['path'];

  // Drupal doesn't accept # as valid path on field input
  $options = array();
  $options['query'] = isset($content['path_query']) ? om_path_query($content['path_query']) : '';
  $options['fragment'] = isset($content['path_fragment']) ? $content['path_fragment'] : '';

  // disables link when active
  $disable_active_link = $disabled ? $path_relative != $uri && $content['path'] != $qpath ? 1 : 0 : 1;
  if (!empty($content['path']) && $disable_active_link) {
    $path = $content['path'] == '<front>' ? '' : $content['path'];

    // there are too many things inside this $link_options which a regular l() can't handle

    //$out .= l($content['link_title'], $content['path'], array('attributes' => $attributes));
    $vars['om_link'] = '<a ' . drupal_attributes($attributes) . ' href="' . url($path, $options) . '">' . $link_option . '</a>';
  }
  elseif (!empty($options['query']) || !empty($options['fragment'])) {

    // base path is not necessary when path is empty but anchor is not or query,
    $vars['om_link'] = '<a ' . drupal_attributes($attributes) . ' href="' . url('', $options) . '">' . $link_option . '</a>';
  }
  else {

    // title with javascript should have div tag
    $script_link = om_string_name($content['link_title'], FALSE);

    // title contains some block elements
    $link_tag = isset($content['php_option']) && $content['php_option'] == 1 || $script_link == 'Script Link' ? 'div' : 'span';

    // useful when you just want a button for getting the content to show and not actually linking to anything
    $vars['om_link'] = '<' . $link_tag . $span_id . ' class="' . $attributes['class'] . '" ' . $span_title . '>' . $link_option . '</' . $link_tag . '>';
  }
  $maximenu_name = preg_replace('/-/', '_', $vars['maximenu_name']);
  $vars['theme_hook_suggestions'][] = 'om_maximenu_submenu_links__' . $maximenu_name;
  $vars['theme_hook_suggestions'][] = 'om_maximenu_submenu_links__' . $maximenu_name . '_' . $vars['key'];
  $vars['theme_hook_suggestions'][] = 'om_maximenu_submenu_links__' . om_string_name($content['link_title']);

  //dsm($vars);
}