coding

Add links to login block

  • 10 January 2013
  • mohit.aghera

In one of my requirement I had two registration for two users. User had two roles. We have to build seperate form for two user registration.

I created two profiles using profile2 module and using profile2reg path module i got the seperate distrinct registration url for both the roles.

By registrating from the specific url user will automatically get the respective role.

Now to give the seperate registration link for user we have to alter registration form using hook_form_alter() function.

Here is the code snippet how to achieve it.

In any case if we want to add some more links to user

Tags: 

Inplace Editing in Drupal 7 with Edit module

  • 10 January 2013
  • mohit.aghera

 

How i manage inplace editing using edit module.
 
In drupal 8 there is inplace edit feature is in drupal core. It is really awesome feature. Now i wanted to achieve same feature in drupal 7 also.
There are lots of alternatives like
1. aloha module
2. Edit module with fape module.
 
I don't know the reason but i selected the second approch. So i installed the edit and fape module.
After successful installation module started behaving very strange like after one inplace edit it was showing error and when we go to other node for editing purpose
it was showing error.
 
Fatal error:

Limit the Depth of comment to certain number

  • 22 November 2012
  • mohit.aghera

In Drupal 7 you might have observed that when you enable the comments on any node at that time it also allows you to add the comments.

In each comment there is link to add the replay, but drupal doesn't provide any management to limit the depth/number of replay using interface or any module.

But we can customize using hook_preprocess_HOOK().

For comment display we have to create hook like themename_preprocess_comment() function in template.php file of theme.

After that we have to find the depth of the comment tree. You can find it using $variables['elements']['#comment']->depth variable. 

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: 

Pages