Drupal Module Review: Services

URL :    Services
Sample Gist:  Request

Client wants to create a mobile application, now asks for JSON endpoints to fetch datas from your Drupal website. The easiest route has always been to create a menu route and a callback. Easy to work and we have control. In this setup things gets complicated when:

  • All these requests can only be accessed by logged in user.
  • Coding gets messy: Like you want to through an output of a view. In some harsh setup we had to get views result set then manually handled output. There are few supportive modules like views_data_export.
  • Need more fine grained control based on permission.
  • Today its json later they might ask for SOAP layer.

A scratch ( i call this) solution may seem attractive and faster but in a large system it all depends on the architecture you set up.

Services module provides robust base for mobile application to website communication. It provides multiple interfaces : XML, JSON etc. It ships with few helpful resources: user, node, views etc. Then you can create custom resource that can be exposed via services.

Here are few lessons I learnt during integration [ More to come ]:


I used session authentication. Services module has a huge handbook that covers in details. But it took some time for me get hang on authentication. Here is gist that based on guzzle which shows sample request to drupal7 services.

Drupal 7 Apache Solr Configuration


Thanks to lullabot for this nice post which produces exact output that it says. In my case i had to make few other changes in my CENTOS cloud server.


1.  Instead of recommended version of drupal apachesolr module; I took the dev version for solr configuration. 

2. You wont be able to access http://localhost:8983  

The reason behind this is firewall if you have iptables enabled . Open /etc/sysconfig/iptables and add following line:

# Tomcat Port
-A INPUT -p tcp --dport 8983 -j ACCEPT

Then restart iptables #/etc/init.d/iptables restart .  Now you can access tomcat server.

3. That article didnt speak much about security.  VISIT I found this post to secure SOLR admin panel. There is truncated tags in that XML . See the github gist  comment to fix this. 

4.  In drupal admin level use http://username:password@localhost:8983/solr/drupal 

5. Setup Tomcat to run on startup . This post of rackspace is useful. I did have to tweak few lines in that shell. I removed java path variables and put correct path to tomcat startup and shutdown shell.


Finally  configure the basic settings for solr inside drupal admin. I used drush solr-index  to index my contents. Thats it , Enjoy SOLR !



https://drupal.org/node/1333076   This post discusses above security and configuration related to admin.


Admin_views Module with multiple user

Module URL:  admin_views

We use this module to provide nice filtering features for our client. In few cases we share create different roles based on client request. Such as, This particular user can only edit his contents or specific content types. A good feature of admin_views is that it does considers user permission and renders admin links based on that. But one problem is that if the site has huge list of contents; its hard to find a single content from a list of thousand items.

To make this user intuitive, we want to show only user contents in Content Management but for specific roles we will show them all. To do that follow these steps:

1. Go to Views and open edit form for “Administration: Nodes” .  Admin_views module utilises this module.

2. Add a contextual Filter Author: uid  . Click on “Provide Default Value” and choose PHP code. Note: If you dont see php code in here then enable PHP filter module from Modules.

3. Now put following snippet in the “PHP contextual filter code” :

global $user;

if( in_array( 'administrator', $user->roles) )
  return 'all';
  return $user->uid;

4. Finally Save the views .

Thats it . Now only administrator can view entire list but for other roles only authored contents will be visible to logged in user.

Using Drush ( Power tool for Drupal ) in Windows XP

At first when I saw drush i thought it’s not that handy as it seems to be. I thought some geek created this just to have fun and feel command line flexibility. But after i dig deeper i found it amazing. If you understand how to use drush you will be amazed by it’s power.

Now what is drush .. drush is a command line shell and Unix scripting interface for Drupal. as stated in here.  The most noteable features of drush from my point of view is :   module enable/disable, update script,  module download, cache clear. Just from command mode i can check latest version of module and dl them and enable them in just simple 3 to 4 commands.

I am not going to briefly explain drush functionality but will try to explain how to run drush in your system in this case Windows XP ( 😛 ) .  Here it goes:

  • Download the latest version of drush from drupal
  • Now open Command prompt and check and set initial settings.
    • Type ‘php’ and press enter if php command is not found then set php.exe path in your Environment
    • Also add the drush path into the environment path
    • By Closing and opening  command prompt again. check by typing ‘drush’
    • If by typing ‘drush’ shows error regarding drush.php open drush.bat file in an editor and  add the abosulute path of drush.php in that bat file.
    • This will fix the drush.php path problem.
  • Let’s play with drush. Open command prompt again and traverse to a drupal installation for example:  ‘cd d:/www/mydrupal’  and then type  ‘drush status’. It will show initial settings of mydrupal installation. If it does not check for settings and environment path.

Drush has some nice extensions. You can play around with them. Here is another simple tip for you. If you study drush you will definately like “drush -v dl ” and ‘drush info” command. “drush info <module_name>” shows particular modules downloadable version and “drush -v dl” can help you to download and copy the file directly into your installation by just 1 single command. But to use ‘drush -v dl’ is little tricky. It uses gzip and tar command to extract the downloaded module file. You can download gzip and tar exe for windows from here.

It seems some ppl did able to use gzip and tar without any hasle but in my case i had trouble with tar. So i hacked into the core of drush and changed the tar command into izarce . If you face problem with tar then go with izarce. It worked for me.

Oops. To use izarce first install the command line version. Then add the izarce location into your environment path. THen goto drush directory and open file ‘drush\commands\pm\package_handler\wget.inc’.  Now find the line which says:

drush_shell_exec(“tar -xf $tarpath -C \”$path\””);

Now replace this with

drush_shell_exec(“izarce -e -d -p”. $path . ” $tarpath”);

It worked for me hope this does for you too. Have a nice drushed life.

[ N.B. At first i tried to use 7zip instead of izarce and gzip+tar but they have some absolute path issue; the solution of which i could not find. So, if you do know of any solution better than this do let me know.

For setting environment   press “windows key+ pausebreak” >> Advanced >> ‘environment variable’ >> now find variable path .. 🙂 enjoy]

My favorite Modules in Drupal

I have been planning to write a post regarding drupal for quite a long time. Today i am enlisting some of the modules which I use most and a sentence or 2 to explain their task:

  1. Administration Menu:
    It’s an elegant Navigation menu for Drupal for Administration. It creates the navigation menu on top of the site in a sleek bar. I always put this in my development and remove the navigation block. Don’t forget to add $closure in your custom theme when you are using this module.
  2. WYSIWYG API : ( Previously TinyMCE )
    An elegant RICH text editor is enough to satisfy the client or me. Though with many unwanted behavior or so.. I still like to use such module in my installation. IMCE is another module to integrate with TinyMCE which supports Image Upload mechanism on Flow.
  3. CCK ( Content Construction Kit ):
    This can add Additional Fields in your custom content. Must have tool.
    Drupal to me is uncomplete without CCK and VIEWS modules. These two can make like as easy as possible. Views helps you to fetch contents they way you want it.. and Theme wizard is a bless.
    To fetch some additional data or Registration form, most time I depend on this module. This has some cool features like sending mail when someone fill ups the form. Must have tool for all.
  6. Date:
    It provides a date field for your contents. Really Helpful.
  7. Acidfree:
    Many may say it’s not ready for production use. But i use it a lot where i need a gallery.  It has some nice features too.
  8. Lightbox2:
    Combine this with Acidfree you will get a nice gallery.
  9. Image :
    If you need an image Content, here you have it.
  10. Pathauto:
    If you are tired of calling your contents by node/1 or node/420 then this can help you to automate or manual entry to change it to meaningful reference.
  11. Calendar:
    To create an Event page, Calendar module is very helpful.
  12. Devel :
    Though this one is a geeky module but it helps a lot to understand how drupal works out.
  13. Contemplate:
    I have not used this in any place but i think it can be helpful for many that’s why i am enlisting it here.
  14. Jquery Update:
    Pretty self explanatory.. i think.

There are many other modules which can be enlisted here but i think these are the basic and must have modules to have to start your work.  I will add more modules later .. please drop you suggestion .

Super Scratch Development-1: Ideas from CodeIgniter & Drupal

There are a good number of developers i have seen who still develop sites using Scratch Development. Each and every one of them have their own excuses over CMS and MVC based frameworks. Even most of the fresh students from universities never heard of Web Application Frameworks ( very sad ). So, guiding new freshers to the world of Web Application Framework is little tough and sometimes they get frustrated. In such cases i let them develop using scratch but give them some tools and ideas from codeIgniter and Drupal. After working with such things sooner they become more interested on newer things like Frameworks.

Here i am not going for details just an overview. Otherwise i have to write a whole e-book 😀 … Is there any good rich guy who can sponsor me to write a book on this .. :))

  1. BASE PATH / Database Operation
    Freshers and other experienced scratch developers mostly uses Relative path ( ./ or ../) to target their image or PHP files. And for database activity i can bet 70% scratch coder uses ( common.php or common.inc) where they put a connect_to_db function which connects to database.For PATH location i usually suggest to use a ‘config.php’ 😀 file and store necessary paths like Image folder, JS etc.. and in your code use such folder location to locate your images and other stuffs.

    Now for database activity… in this case i take the risk and usually introduce ActiveRecord of CodeIgniter to the freshers. And for this reason i am very thankful to Hasin Hayder for separating ActiveRecord from CodeIgniter. I used his separation :D.

  2. Template Engine ( tiny but strong / Smarty)
    PHP template Engine can reduce coding lines and it gives a great opportunity to reshape or change the orientation of the site as clients and bosses likes to change their minds very often. In my personal opinion i liked ‘tiny but strong’.

    Ideas From drupal

    : I very much 😀 like the block mechanism of drupal. In drupal you can put your block in any particular place like left sidebar, right sidebar, footer etc even by theme customizing you can create your particular region where you can put your block . So, this can be easily inherit by using tiny but strong. By using a database table which specify the position of a particular block and some individual block code; you can achieve such functionality. Even the header and footer can be handled more efficiently.

  3. TinyMCE / FCKeditor
    In every web project there are always a number of static pages needs to be handled 😦 like contact us, about us etc. Such cases can be handled by Rich Text Editors like TinyMCE and FCKeditor. Keep the contents of those static pages inside the database. And provide TinyMCE ( my personal favorite ) to edit such contents. In those pages you can retrieve the body content from database.

    you can see their comparison with others 😀

to be continued …………………………………….. 😀