You are here

function hansel_action_add_link_to_node_get_crumbs in Hansel breadcrumbs 7

Same name and namespace in other branches
  1. 8 hansel.actions.inc \hansel_action_add_link_to_node_get_crumbs()

Callback for the "add link to node" breadcrumb action to generate the crumbs.

Parameters

array $arguments:

Return value

array

2 string references to 'hansel_action_add_link_to_node_get_crumbs'
hansel_hansel_action_types in ./hansel.module
Implements hook_hansel_action_types().
hook_hansel_action_types in ./hansel.hooks.inc
Define action types.

File

./hansel.actions.inc, line 57
Hansel breadcrumb actions

Code

function hansel_action_add_link_to_node_get_crumbs($arguments) {
  global $_hansel_flags;
  global $language;
  if (drupal_strtolower(hansel_arg(0)) == 'node' && is_numeric(hansel_arg(1))) {
    $href = 'node/' . hansel_arg(1);

    /**
     * Use the menu item title if available.
     * The menu item title is used to active the menu items, and is used by the
     * add parents breadcrumb action. So if available, we should use this one.
     * This is to fix the activation of menu items when the node title differs
     * from the menu item title.
     */
    $query = db_select('menu_links', 'c');
    if (module_exists('i18n_menu')) {
      $query
        ->fields('c', array(
        'menu_name',
        'mlid',
        'link_title',
        'language',
      ));
      $query
        ->condition('c.language', array(
        $language->language,
        LANGUAGE_NONE,
      ));
    }
    else {
      $query
        ->fields('c', array(
        'menu_name',
        'link_title',
      ));
    }
    $query
      ->condition('c.link_path', $href)
      ->condition('hidden', 0)
      ->orderBy('depth')
      ->range(0, 1);
    $link = $query
      ->execute()
      ->fetchObject();
    if ($link) {
      if (module_exists('i18n_menu')) {
        $i18n_mode = i18n_menu_mode($link->menu_name);
      }
      else {
        $i18n_mode = FALSE;
      }
      if ($i18n_mode == '5' && $link->language == LANGUAGE_NONE) {

        // Menu is in "Translate and localise" mode and the menu item is "Language neutral" (translatable).
        $link_title = i18n_string_translate(array(
          'menu',
          'item',
          $link->mlid,
          'title',
        ), $link->link_title, array(
          'langcode' => $language->language,
          'sanitize' => FALSE,
        ));
      }
      else {

        // Menu is in "Fixed language" mode, or item is localized (not in "Language neutral").
        $link_title = $link->link_title;
      }
      return array(
        array(
          'title' => $link_title,
          'href' => $href,
        ),
      );
    }
    elseif ($node = node_load(hansel_arg(1))) {
      return array(
        array(
          'title' => $node->title,
          'href' => $href,
        ),
      );
    }
  }
  return array();
}