How to make custom behavior in Openlayers module with Drupal 7

Drupal with Openlayers

Couple of days back I was working with Openlayers in one of my project in D7. I got stuck with some functionality which forced me to make custom behavior which should work with Openlayer module in Drupal 7. I found Openlayers has very less documentation so I thought to write this blog. I will make some introduction about how to start with creating custom behavior which work with Openlayers. I am not focusing on some particular functionality but on giving base to your functionality.

I am assuming you know how to configure Openlayers and display map in Drupal 7.  So , here’s the situation you faced that you need to achieve some functionality which Openlayers don’t provide and then you have to create some module which should work with Openlayers.

Next step is to make a custom module . Go to sites/all/modules/ and create your module directory containing files

  • module_name.module

Also create some more directory in your module directory like

  • include — [It will contain all .inc files]
  • js — [javascript files ]
  • css — [css files ]

Now we will write some things in your modules .info file.

name = Module name
description = Allow you to draw polygon on map and it will search locations on map based on polygon draw.
core = 7.x
package = “Openlayers”
dependencies[] = openlayers

files[] = module_name.module
files[] = include/

Step 2: We will add some code in modulename.module file.


// implementing hook_init()

function modulename_init(){

// here we are adding our css and javascript file
         drupal_add_js(drupal_get_path(‘module’, ‘open_draw’) .
    drupal_add_css(drupal_get_path(‘module’, ‘open_draw’)  .

// implementing hook_openlayers_behaviors()
function modulename_openlayers_behaviors() {
  return array(
         ‘openlayers_behavior_region_click’ => array(   
    ‘title’ => t(‘Polygon search’),
    ‘description’ => t(‘It will allow search on maps when user will draw polygon on map’),
    ‘type’ => ‘layer’,
    ‘path’ => drupal_get_path(‘module’, ‘open_draw’) . ‘/include’,
    ‘behavior’ => array(
        ‘file’ => ‘’,
      ‘class’ => ‘openlayers_behavior_drawfeatures’,
      ‘parent’ => ‘openlayers_behavior’,

Step 3: We will make in our include directory and add some behavior in it.


 * behavior
class openlayers_behavior extends openlayers_behavior {
   * Provide initial values for options.
  function options_init() {
    return array(
      ‘element_id’ => ”,
      ‘feature_types’ => array(),
      ‘feature_limit’ => 0,

  function options_form($defaults = array()) {
    $features = array(
      ‘polygon’ => t(‘Polygon’),

    return array(
      ‘feature_types’ => array(
        ‘#title’ => t(‘Available Features’),
        ‘#type’ => ‘checkboxes’,
        ‘#options’ => $features,
        ‘#description’ => t(‘Select what features are available to draw.’),
        ‘#default_value’ => isset($defaults[‘feature_types’]) ? $defaults[‘feature_types’] : array(),

That’s it now just enable your module and you can see your behavior in behavior section of Openlayers map settings.

Of course now our behavior are not doing anything we just able to see our behavior’s settings in Openlayers map settings. In order to make behavior functional now you have to just add javascript or Jquery in you /js directory and css in /css directory.


Step by Step : How to implement Facet Search on data in Drupal 7

In this blog I will help you in setting up Facet search functionality on your  data in Drupal 7. However , If you are thinking about creating website where you can show your Big Data and with the help of facet search your website user can actually find specific data related to them. This blog will probably help you.

The Faceted Search module provides a search API and a search interface for allowing users to browse content in such a way that they can rapidly get acquainted with the scope and nature of the content, and never feel lost in the data. More than a search interface, this is an information navigation and discovery tool.

In order to make such functionality you need to install couple of modules in your site. We will first make a Indexing engine which will index all your data and then we make blocks of specific data which will allow you to filter  all related data to itself.

Modules to install for implementing Facet Search:

  1. Facet API
  2. Search API
  3. Database search
  4. Search Facets
  5. Search Views
  6. Entity API

We are done with installing and enabling above modules.

Steps to follow:

  1. Create content type and add fields in respective content type.
  2. Configure the search server
  3. configure the search index
  4. Add fields on in Facet API
  5. Create a complete view  of your data

Step 1. Create content type and add fields in that:

Let’s take an example we created content type

  • Title : Company
  • Fields : Address
  • Fields : County

Now just create content of above content type and add data into it.

Right now we have content with data into it and we have modules. Now we need to configure above modules as per our functionality on data.

Step 2. Configure the Search server:-

Go to configuration admin page (configuration/admin) in your Drupal 7 site and click on search API in Search and metadata section . you should be now on Search configuration setting. We will create a search engine for our data. You should see page like below :

Search configuration

Now click on Add server link .Give name to your server I gave (MYSQL) , Choose database service for your service class and click create server. Your server should be  like below.


Step 3. Configure the search Index:

Now we will make our search index which will index all data from using search server and database server. It will do indexing as user search for data on site and give fast result. Go back to search API settings and click on Add Index link. You should be on below page now.


Values for above form:

  • Index name : Business Information
  • Item type: Node
  • Server: MYSQL which you create earlier
  • Index items immediately : Checked

Click on create Index. Now we will select which field to be indexed from our data so we will select fields we want . In our case we will select

  • content type
  • Address
  • Title
  • County

and click save configuration .

What just happened ?

we created our database server , Index server and added fields which need to be index. As you added fields for indexing Facet API actually make Facet blocks of those fields . don’t focus on them right now we will enable them later.

Now run Cron in your site which populate the Index.

Step 4. Create a view of your data which need to be Indexed and Displayed to your site user :

Install Views and enable it . Go to Structure > Views. click add new view. Select below values for each field:

  • Show content : Business Information “This will be name of your Search server”
  • Create a page: checked
  • Path: node
  • Display format: Table

Your view information look like below:


Click on continue  & edit button . Now in the Fields section click on add fields and Filter Index node . Add Index fields you want to show to your user. Your selection will looks like below.


Complete all configuration of specific field and click Apply Display . You are done with creating view . You are now able to see this view on your front page(/node).

Next step is to enabling all blocks of your facet search . Earlier we added fields which need to be Indexed . Actually when you add fields for indexing Facet API it create Blocks of those fields respectively. You have to just enable them from Search settings.

Step 5. Enable Facet block from Search settings :

Go to configuration and click on Search API from search and metadata . Now just click on edit in Index . You are able to see various configuration options like below.


Click on Facets and enable facets you want . When you enable and save configuration. It will create Blocks of respective fields .

Step 6. Enable your Facet block from Blocks:

Now go to structures and blocks . Here you are able to see your facet block in Disable section just enable them in any regions of your theme.

congratulation your site is ready. Visit your home page and it should  look like below . As you select options from blocks your main view show you data as per your selection .


Facet API have many configuration options . You should take a look to them like showing selection in Blocks in Checkbox etc. However , facet API not able to give you Multiple Facet search functionality . So , I am now working on developing custom module of widget and behavior which will give functionality of Multiple facet selection search . Facet API have OR and AND but only AND works not OR among fields.

Please free feel to ask your queries related to Facet search and If you need some more blog’s on Facet search for specific functionality or configuration or custom modification in Facet API then do comment probably I will help you by writing blog on respective.

Thanks to Chetan , Anirudha , Sonali for reading Draft of this .

Setup your Drupal and ftp in the Amazon EC2 micro instance

In this blog i will drive you through setting up Drupal project instance on  Ec2 micro instance of AWS and setting up ftp on your Drupal instance. Before this , of course you have to registered with AWS which is straight forward .

So , what we will understand from this blog :-

  1. Choosing OS and assigning some security rules on our instance .
  2. How to access our instance and play around it ?
  3. Setting up LAMP on our AWS micro instance
  4. Setting up ftp on AWS micro instance
  5. Managing your Drupal project using ftp connection using filezilla

Once you  are registered with AWS you have to login into your account . Among the AWS services just click on EC2 link which is nothing but a virtual server in the cloud . It will redirect you to EC2 dashboard where you can mange all your instance . Now for creating new instance follow below steps:-

  1. Just click on Launch instance select Classical wizard and click continue .
  2. Now you have to select Amazon Machine Image (AMI) from one of the tabbed lists below by clicking its Select button .
    Lets say we select Ubuntu 12.04 LTS .
  3. Next leave default settings except just select micro instance from the instance type because its free to use and click continue .
  4. Next again leave default setting and click continue .
  5. Next again leave default setting and click continue .
  6. Now you have to give name of your key and value . I recommend give key value name more sensible with your project and click continue .
  7. Now select creating a new key pair as we are new we don’t have exist key pair . Give name to your key pair file it should make sense with regards to your project . Download your keypair.pem file and save at a safe place because we need this file later .
  8. Next select create a new security group . Here we will assign some security rule and enable HTTP , ssh and ftp connection to our instance . HTTP port range is 80 , ssh port range is 22 , for ftp select custom TCP rule and give port range 21-22 . About source you can give any IP range as you need or just leave default for now.
  9. Just click continue and launch instance . Your instance will be running in some time as AWS will take some time to run your instance .

Now our EC2 micro instance is running . You can check out from your dashboard .

Now we setup LAMP in our Ubuntu 12.04 LTS instance . For this we access our Ubuntu instance from terminal and setup LAMP in that. Below are the steps to access and setup your LAMP in Ubuntu 12.04 LTS instance .

  1. Open your terminal and go to the directory where you stored your key pair file .pem file then run this command into your terminal sudo ssh -i file_name.pem .
  2. It will give you Ubuntu prompt in your terminal . You can understand like this that now you are logged in into your Ubuntu machine and you can do anything over their . The main thing here is you have to run all commands with “sudo” or as a root user which works on file system directory .
  3. In order to setup LAMP we will install three packages in it . Run these command from terminal :-
  • sudo apt-get install apache2
  • sudo apt-get install mysql-server
  • sudo apt-get php5 php-pear php5-mysql php5-suhosin

That’s it your LAMP environment is ready . You can check it by navigating your instance URL that is for example look like this in browser . It will give you message Localhost is working something like that .

Till here we got our LAMP environment running into our EC2 instance . Now we install our Drupal 7 instance in it . Here in Ubuntu instance we don’t have any ftp connection with ftp client or server. So we can use SCP for taking Drupal tarball from our local instance or we can use wget utility of Linux to download Drupal from its URL . Below are steps to install Drupal 7

  1. cd /var/www/
  2. wget
  3. tar xvf drupal-7.12.tar.gz
  4. mv drupal-7.12 drupal

Below is a link which can tell you how to install Drupal in Linux . Just follow all those steps .

When you setup with your mysql database and Drupal configuration then just browser link like for example :

It will take you to your Drupal site .

Now we will see how to setup ftp on Drupal instance .Why we need ftp for Drupal instance . In order to work on Drupal we have to use many modules ,themes  and libraries . So we have to upload those things on site . we can achieve this with SCP but that will be more difficult because you have to do via command line .  Here we will see how to setup Filezilla ftp on Drupal site which is on AWS EC2 . Below are the steps to setup filezilla as a ftp client .

  1. Install filezilla  into your local system :- sudo apt-get install filezilla
  2. Now open filezilla click on file > site manager
  3. Enter the details of your site here like :-
  • HOST –
  • Port– 22
  • Protocol – SFTP(SSH file transfer protocol )
  • Logon Type – Normal
  • User – ubuntu
  • Password – ubuntu . Then click on ok don’t click on connect this time .
  1. Now click on Edit> Settings > SFTP and addkeyfile . Navigate your .pem file here . It will ask you to convert .pem file just select ok . Now filezilla have your instance credentials to connect and everything is good to connect to your Drupal instance .
  2. Now click on file > site manager > connect

Now you can transfer all files from your local to Drupal instance .

I hope you enjoyed this blog. Please feel free to comment and send queries to me .

Reference :-

Thanks to Sonali , Anirudha , Chetan for reading draft of this