New hooks to be added in Drupal 7.17

  • 6 November 2012
  • mohit.aghera

There are two new hooks added in Drupal 7.17 core, which is scheduled to be released on 7 November 2012.


Introduced in Branch: 7.x, 8.x
Introduced in version: 7.17

Drupal 7.17 introduces a new hook, hook_entity_view_mode_alter(), which allows modules to programmatically alter the view mode when an entity is being displayed.

<?php
  function mymodule_entity_view_mode_alter(&$view_mode, $context) {
    // Change the view mode to teaser for anonymous users viewing a node.
    if ($context['entity_type'] == 'node') && user_is_anonymous()) {
      $view_mode = 'teaser';
    }
  }
?>


The hook also exists

Tags: 

How to check whether any node is accessed in past or not

  • 2 November 2012
  • mohit.aghera

During one of my project development I need to check whether in past any node is accessed by logged in user or not.

Fortunately node module and “history table of database ”came to help me.

In node module there is function  node_last_viewed($nid) which returns the last unix timestamp of node access time.

Basically I was using Og forum module so I wanted to check whether any forum topic is viewed previously by logged in user or not.

So first I filtered all the groups of the logged in user.

After that I checked field_data_group_audience table which stores the relation between group node and

Tags: 

Life after the revolution of open source transition

  • 26 October 2012
  • mohit.aghera

Some days ago I was reading  The Cathedral and the Bazaar: Musings on Linux and Open Source by an Accidental Revolutionary (abbreviated CatB) is an essay by Eric S. Raymond on software engineering methods, based on his observations of the Linux kernel development process and his experiences managing an open source project, fetchmail.

At the end I found really interesting conclusion, I am posting here.

Tags: 

Making new variables for use in templates file

  • 23 October 2012
  • mohit.aghera

 

The variables process functions also allow you to define additional variables in your theme.
 
To create a new variable, you must declare the function in the template. php file. 
 
In order for your theme to have its preprocessors recognized, the template associated with the hook must exist inside the theme.
 
If the template does not exist in your theme, copy (or create) one and place it in the theme directory. 
 
The syntax is the same as that just used for intercepting and overriding a variable, as seen above.
Tags: 

Drush variable-set and variable-get commands

  • 22 October 2012
  • mohit.aghera

Drush is the most useful command prompt tool for Drupal Developer. In previous posts I discussed about installing Drupal using Drush.

Using Drush we can also set the values of the variables and we can also get/see the values of the variables.

 

The commands variable set, variable-get, and variable-delete allow you to configure, view, and delete Drupal configuration variables stored at the variable table.
 

Listing of various available variables:

Drush  variable-get will display list of all the variables 

 

$ drush variable-get
admin_theme: "bartik"
clean_url: TRUE
comment_page: 0

Pages