Skip to main content

Drupal 7 - Views bread crumb module

There is no module which entirely support to give the bread crumbs on the views pages. So I created one module and tried to contribute to the community which contributed a lot to my carrier. I end up to merge my code with the other contributed modules which provides the breadcrumbs.

Here is my sandbox project page:- https://drupal.org/sandbox/rakeshjames/2049937

1)  views_breadcrumb.info 

name = Views breadcrumb
description =  Setting bread crumbs for all the view's pages.
dependencies[] = views
core = "7.x"
configure = admin/structure/block/manage/views_breadcrumb/views_breadcrumb_block/configure

2)  views_breadcrumb.module 

<?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,
    'pages' =>BLOCK_VISIBILITY_LISTED,
  );
  return $blocks;
}

/**
 *Implements hook_block_view().
 */
function views_breadcrumb_block_view($delta = '') {
  $block = array();
  switch ($delta) {
    case 'views_breadcrumb_block':
      global $user;
      global $base_url;
      $title_node_value = '';
      $count = 0;
      $block['subject'] = NULL;
      $path = current_path();
      $path_explodeArray = explode ("/", $path);
      $array_count = count($path_explodeArray);
      $last_value = intval($path_explodeArray[$array_count - 1]);
      if (is_numeric($last_value)) {
        $node = node_load($last_value);
        if(empty($node)) {
          $title_node_value = '';
        }
        else {
          $title_node_value = $node->title;
        }
        for ($i = 0; $i < $array_count - 1; $i++) {
          $arryTo_implode[$i] = $path_explodeArray[$i];
        }
        $path = implode("/", $arryTo_implode);
      }
      $access = db_query("SELECT access_callback  FROM {menu_router} WHERE path LIKE '%$path%' AND  page_callback LIKE '%views_page%'")->fetchField();
      if (empty($access)) {
        $block['content'] = drupal_set_message("Views breadcrumb block module only for views pages, please ".l('configure','admin/structure/block/manage/views_breadcrumb/views_breadcrumb_block/configure')." correctly.");
      }
      else {
 $plid = db_query("SELECT plid  FROM {menu_links} WHERE link_path LIKE '%$path%'")->fetchField();
 for ($i = 0; $plid > -1; $i ++) {
   if ($plid == 0){
     $plid = -1;
   }
   else {
     $result = db_query("SELECT plid, link_path, link_title FROM  {menu_links} WHERE mlid = $plid");
              foreach ($result as $value) {
       $plid = $value->plid;
       $data[$i]['link_path'] = $value->link_path;
       $data[$i]['link_title'] = $value->link_title;
$data[$i]['plid'] = $value->plid;
       $count++;
     }
   }
 }
      $breadcrumb[] = l('Home', $base_url);
      for ($j = $count - 1; $j > -1; $j --) {
        $breadcrumb[] .= l($data[$j]['link_title'], $data[$j]['link_path']);
        $count_mlid_plid = $data[$j]['plid'];
      }
      if (empty($title_node_value)) {
      $breadcrumb[] .= l(drupal_get_title(), $base_url.$_SERVER['REQUEST_URI']);
      }
      else {
        $previous_link_path = db_query("SELECT router_path FROM {menu_links} WHERE  link_path LIKE '%$path%'")->fetchField();
        $previous_link_title = db_query("SELECT link_title FROM {menu_links} WHERE  link_path LIKE '%$path%'")->fetchField();
        $breadcrumb[] .= l($previous_link_title, $previous_link_path);
        $breadcrumb[] .= t($title_node_value);
      }
      $output = drupal_set_breadcrumb($breadcrumb);
      $block['content'] = $output;
      }
      break;
  }
  return $block;
}

3)  README.txt 

INSTALL
==========

1. Extract module into /sites/all/modules folder.
2. Enable "Views breadcrumb" and
   "Views breadcrumb configuration" click the configuration button on /admin/modules page.


USAGE
==========

Go to admin/structure/block/manage/views_breadcrumb/views_breadcrumb_block/configure
and only do the steps follows,

     1. Go to 'Show block on specific pages' option and select "Only the listed pages"
     2. copy and paste the path of only views pages
     3. Go to 'REGION SETTINGS' and put it into any of the regions.
     4. Save block.


CREDITS
=========

Module was developed by Rakesh James (https://drupal.org/user/1177822,
http://3icube.com/)

Module development was not sponsored by anyone. It was created for the love of Drupal.

Comments

Popular posts from this blog

How to set the page title in Drupal 8? drupal_set_title() in Drupal 8 ? drupal_get_title() in Drupal8?

Using the following lines of code in hook_form_alter()  , able to set the title and get the title after saving the code do CLEAR CACHE drupal_set_title() in  Drupal8 $request = \ Drupal :: request (); if ( $route = $request -> attributes -> get (\ Symfony \ Cmf \ Component \ Routing \ RouteObjectInterface :: ROUTE_OBJECT )) { $route -> setDefault ( '_title' , 'New Title' ); } drupal_get_title() in Drupal8 $request = \ Drupal :: request (); if ( $route = $request -> attributes -> get (\ Symfony \ Cmf \ Component \ Routing \ RouteObjectInterface :: ROUTE_OBJECT )) { $title = \ Drupal :: service ( 'title_resolver' ) -> getTitle ( $request , $route ); }

How to create the Popup or modal in Drupal 8?

The following code will help you to create the popup in Drupal 8.  use \ Drupal \ Core \ Ajax ; function testingPopup () { $response = new AjaxResponse (); $title = $this -> t ( 'Title for the Popup.' ); $form [ '#attached' ][ 'library' ][] = 'core/drupal.dialog.ajax' ; $response -> setAttachments ( $form [ '#attached' ]); $content = '<div class="test-popup-content">' . 'Content in HTML format' . '</div>' ; $options = array ( 'dialogClass' => 'popup-dialog-class' , 'width' => '75%' , ); $modal = new OpenModalDialogCommand ( $title , $content , $options ); $response -> addCommand ( $modal ); return $response ; } You can call the function testingPopup() , you will get the popup.

How to configure Drupal7, varnish, authcache2 and ESI in Nginx server?

This is step by step procedure for, how to configure the authcache, varnih and ESI for the drupal7 project in NGINX erver. To configuring the Nginx Server use the procedure from document " http://www.geoffstratton.com/2014/03/nginx-php-fpm-apc-ssl-drupal/ " Well, make sure your nginx server is up and running. 1.Configuring the Authcache module.      Download the module from https://www.drupal.org/project/authcache    Enable only the authcache module    Go to admin/reports/status , then you can see the Authcache area is red and saying that there is no back end has been configured.   2.Configure Varnish on the back-end[nginx server].     Using the Following commands,       $ curl http://repo.varnish-cache.org/debian/GPG-key.txt | sudo apt-key add -     $ echo "deb http://repo.varnish-cache.org/ubuntu/ precise varnish-3.0" | sudo tee -a /etc/apt/sources.list     $ sudo apt-get update     $ sudo apt-get install varnish       Configure Varnish: