How to grab the contextual filter value in views theming ?

Since the contextual filter isn’t inside the [fields] array of the view but we can access its value in our template file using this functionality in views itself

  • In footer add a global text area
  • Select PHP code in the text format select box
  • Enter the following code

  • $view = views_get_current_view();

    Make sure to include php opening and closing tags and read this one if you have multiple views in same page.

    Now in our views template file with $view->args we can get the contextual filter value.

    In drupal , How to show the parent and child taxonomy term as a menu?

    Say I have a vocabulary like this
    Term1
    –Sub term1
    –Sub term2
    Term2
    –Sub term3
    –sub term4
    Term3
    Term4
    Now I would like to show the list of Parent term and its Child terms as menu.To generate menu using the parent and child taxonomy terms relationship, there are some contrib module like Taxonomy menu , Taxonomy menu block , Nice Taxonomy Menu etc and we can also generate parent and child taxonomy terms relationship using views ( see this http://drupal.stackexchange.com/questions/28076/how-to-show-the-parent-and-child-taxonomy-term?lq=1 ).

    To generate menu using parent and child taxonomy terms relationship, i used Taxonomy menu block and got some bad experience.

    • After creating menu using Taxonomy menu block, we can disable some term from menu section so that they do not show in menu, this is really easy and disabling menu items works but the menu items start appearing again once if we run cron or submit content for that term again or update that term which is not expected and confusing because we don’t want to show it at all.
    • Vocabulary terms order and taxonomy menu section terms order are not sync.
    • If anyone update a term from taxonomy menu section that will not affect in vocabulary section, this is also confusing

    For term visibility we can set status flag to every term. For this there is a nice contrib module Taxonomy Term status. But this one is not working properly with taxonomy menu block and not sync.

    So apart those taxonomy menu related module, we can achieve our goal using two contrib module. One is Views Tree and another one is Taxonomy Term status. Because Views Tree project page says

    This module provides a tree-based style plugin for Views. It is equivalent to the tree-based style template from Views 1.

    It is based off of the list style. Although it generates a nested view, there is still only a single query run for the view making it quite performant.

    Compatibility:

    This module has been tested and used with the following relationship-oriented modules:
    Taxonomy (in core) – parent/child relationships.

    Views Tree with Taxonomy Terms:

    First, create a new term view using the fields row style / unformatted list of fields (it is important that the tree style not be chosen now). Then:

    • Add relationship for taxonomy term: parent term
    • Add field term id (do not use relationship) and exclude it from display
    • Add field term id with relationship, exclude from display
    • Add any fields you want to display, like term name, term description, etc…
    • Change style / format plugin to Tree (Adjacency model)
    • Set Main field to Term ID
    • Set Parent field to Term ID with parent relationship
    • Set FILTER CRITERIA Taxonomy term: Published (Yes), so that only published terms will be visible.

    Above instructions are taken from https://www.drupal.org/node/1424414#comment-6434062
    After that we will get a tree structure like this:

    • Term1
      • Sub term1
      • Sub term2
    • Term2
      • Sub term3
      • sub term4
    • Term3
    • Term4

    Now by applying some css we can make this tree structure into menu.
    For more info about this visit following links:
    https://www.drupal.org/node/1493366

    In drupal webform e-mail from is not being passed in email sender header

    In drupal webform generated e-mail is grabbing the default email from the site information as a Sender header-information.

    Over SMTP when a message is submitted, the SMTP envelope (sender, recipients, etc.) is different from the actual data of the message. The Sender header is used to identify in the message who submitted it. This is usually the same as the From header, which is who the message is from. However, it can differ in some cases where a mail agent is sending messages on behalf of someone else.

    In drupal, webform generated email sender header and from header is not same, so when anyone check webform generated email using SMTP client they see Sender header instead of From header. After some investigations I figured out that in the mail headers the recipient is written nicely by webform (like To: foo@customer.com), the from is also written nicely by webform (like From: from@customer.com). But the webform is grabbing the default email from the site information ( /admin/settings/site-information) and  sender is written by this address (like Sender: bar@customer.com).  what is causing the problem and confusion.

    It looks like Drupal core is responsible for these headers, I know that Webform isn’t adding them.So basically, it’s going to be forced on to any e-mails sent by Webform. The spam argument is valid though, since Drupal is sending the e-mail from it’s server, giving e-mails a different Sender could cause e-mails to be marked as spam on the receiving end. If you really want to get rid of these headers, you can implement hook_mail_alter() in a custom module and rewrite the headers.
    /**
    * Implementation of hook_mail_alter().
    */
    function mymodule_mail_alter(&$message) {
    if ($message['id'] == 'webform_submission') {

         $message['from'] = $from;
         $message['headers']['From'] = $from;
         $message['headers']['Sender'] = $from;
         $message['headers']['Return-Path'] = $from;
         }

    }

    For more information , Please go through the follow links

    https://www.drupal.org/node/461324 and https://www.drupal.org/node/1804214

    In drupal 7, how to access additional user profile fields ?

    In Drupal 7 we can add new fields to the user profiles using:

    Configuration -> People -> Account Settings -> Manage Fields (admin/config/people/accounts/fields)

    But those added fields are not part of $user. To access those fields we need additional step like this.

    <?php
    global $user;
    $user_fields = user_load($user->uid);

    $first_name = $user_fields->field_firstname[‘und’][‘0’][‘value’];
    $last_name = $user_fields->field_lastname[‘und’][‘0’][‘value’];
    ?>

    Getting a visitor’s location (i.e. city) using JavaScript

    One third party service you could use is http://ipinfo.io . You can use it client-side. Here’s a simple jQuery example:

    $.get("http://ipinfo.io", function(response) {
    console.log(response.city);
    }, "jsonp");

    N.B: ipinfo.in gives a 401 error for HTTPS access if you’re not paying them. It says that you need to pay to access via HTTPS. For more info please visit this http://ipinfo.io/pricing .

    There is an another service is http://freegeoip.net . It consists in submitting a very simple Ajax POST request to http://freegeoip.net/json. Once you receive your location information, in JSON, you can easily get visitor’s city.
    jQuery.ajax( {
    url: ‘//freegeoip.net/json/’,
    type: ‘POST’,
    dataType: ‘jsonp’,
    success: function(location) {
    console.log(location.city);
    }
    } );

    JSON callbacks are supported by adding the callback argument to the query string. You can also use this one instead of AJAX post.Just add the callback parameter.
    $.get("http://freegeoip.net/json/?callback=?", function(response) {
    //if your site is using SSL then use https instead of http
    var user_location = response.city;
    console.log(user_location);
    });

    In drupal 7 how to save a node form with default values

    In drupal 7, if we want to embed node form with default values we can do it in our custom module. Like this:

    function custom_module_node_form_save(){
    if (isset($_REQUEST['filegroup-add'])) {
    $node = new stdClass();
    $node->type = 'file_group';
    $node->uid = $user->uid;
    $node->name = (isset($user->name) ? $user->name : '');
    $node->language = 'und';
    $node->status = 1;

    $node->title = $_REQUEST['filegroup-add'];
    $node->language = 'und';
    $node->field_cat['und'][0]['target_id'] = $_REQUEST['cat_id'];

    node_object_prepare($node);
    node_save($node);
    }
    }

    Datatables warning(table id = ‘example’): cannot reinitialise data table

    I am working with datatables example and getting an error like this when loading page: Datatables warning(table id = ‘example’): cannot reinitialise data table. To retrieve the DataTables object for this table, pass no arguments or see the docs for bRetrieve and bDestroy.

    This problem occurs if we initialize dataTable twice.Then we have to remove the first.

    On the other hand we can destroy the old datatable in this way also before creating the new datatable use the following code :
    $(“#example”).dataTable().fnDestroy();

    There is an another scenario ,say you send more than one ajax request which response will access same table in same template then we will get error also.In this case fnDestroy method doesn’t work properly because you don’t know which response comes first or later.Then you have to set bRetrieve TRUE in data table configuration.That’s it.

    Some useful jQuery links

    http://web.enavu.com/tutorials/7-amazing-presentation-slides-to-teach-you-how-to-code-with-jquery/

    jquery data table:
    http://www.sharemycode.com/item/view/95/jquery-datatables-plugin-example-with-php-mysql

    Jqgrid:
    http://www.trirand.com/blog/jqgrid/jqgrid.html

    Flexigrid:
    http://flexigrid.info/

    Bootstrap look for jQuery UI:

    http://addyosmani.github.com/jquery-ui-bootstrap/
    http://wijmo.com/widgets/wijmo-open/

    js framework

    http://codebrief.com/2012/01/the-top-10-javascript-mvc-frameworks-reviewed/?utm_source=javascriptweekly&utm_medium=email

    CodeIgniter Session Problem in IE

    I faced this problem many times and I found that the problem is not of the session class of Codeingniter but it is the problem of IE.  CI’s session library creates standards-compliant cookies that work reliably on all web browsers except for Internet Explorer 6,7,8 and so on.  The reason being, Internet Explorer doesn’t follow standards (link).  Shame on IE !

    Please take a look on your cookie settings in /application/config/config.php A CI Remove  underscores from the cookie name (link). This can be done by changing:

    $config['sess_cookie_name']        = 'ci_session';

    to
    $config['sess_cookie_name']        = 'cisession';

    Also remove any underscore in $config[‘cookie_prefix’] since it is prefixed to the cookie name.