You are here

views_breadcrumb.module in Views breadcrumb 7

Same filename and directory in other branches
  1. 8.2 views_breadcrumb.module
  2. 8 views_breadcrumb.module

This module will provide a block that will helps to set the bread crumb for views pages.

File

views_breadcrumb.module
View source
<?php

/**
 * @file
 * This module will provide a block that will helps to set the bread crumb 
 * for views pages.
 */

/**
 * Implements hook_block_info().
 */
function views_breadcrumb_block_info() {
  $blocks['views_breadcrumb_block'] = array(
    'info' => t('Views breadcrumb block'),
    'region' => 'sidebar_first',
    'cache' => DRUPAL_CACHE_PER_PAGE,
  );
  return $blocks;
}

/**
 * Implements hook_block_view().
 */
function views_breadcrumb_block_view($delta = '') {
  $block = array();
  switch ($delta) {
    case 'views_breadcrumb_block':
      $block['subject'] = NULL;
      $block['content'] = breadcrumb_display();
      break;
  }
  return $block;
}

/**
 * @return array|null
 *   breadcrumb link
 */
function breadcrumb_display() {
  global $base_url;
  $count = 0;
  $path = current_path();
  $access = db_query("SELECT m.access_callback  FROM {menu_router} m WHERE m.path LIKE :path AND  m.page_callback LIKE :views_page", array(
    ':path' => $path,
    ':views_page' => 'views_page',
  ))
    ->fetchField();
  if (empty($access)) {
    $output = drupal_set_message(t('Views breadcrumb block module only for views pages, please <a href="@url">configure</a> correctly.', array(
      '@url' => url('admin/structure/block/manage/views_breadcrumb/views_breadcrumb_block/configure'),
    )));
  }
  else {
    $plid = db_query("SELECT ml.plid  FROM {menu_links} ml WHERE ml.link_path LIKE :path", array(
      ':path' => $path,
    ))
      ->fetchField();
    for ($i = 0; $plid > -1; $i++) {
      if ($plid == 0) {
        $plid = -1;
      }
      else {
        $result = db_query("SELECT ml.plid, ml.link_path, ml.link_title FROM  {menu_links} ml WHERE mlid = :plid", array(
          ':plid' => $plid,
        ));
        foreach ($result as $value) {
          $plid = $value->plid;
          $data[$i]['link_path'] = $value->link_path;
          $data[$i]['link_title'] = $value->link_title;
          $count++;
        }
      }
    }
    $breadcrumb[] = l(t('Home'), $base_url);
    for ($j = $count - 1; $j > -1; $j--) {
      $breadcrumb[] .= l($data[$j]['link_title'], $data[$j]['link_path']);
    }
    $breadcrumb[] .= l(drupal_get_title(), $base_url . '/' . $path);
    $output = drupal_set_breadcrumb($breadcrumb);
  }
  return $output;
}