Drupal Planet Posts

Tools for developing in Drupal 7

What are useful tools for developing code in Drupal? Here's a small list that I always have at arms reach when programming. The must is the Devel module, it's a suite of modules containing helper functions. One of these useful functions is dpm(), which prints out a variable to the green message area of the page, it is the same area which drupal_set_message prints to.

How to add a tab to the User Profile page in Drupal 7

What we wanted to do was display on each user profile a list of all the events users create. Especially because the url of events are generated randomly and create a url impossible to remember. To do this we had to implement the hook_menu() in a custom module, called "yourmodule" in this example. What is important is that the path "user/%user/events" (where %user is the user ID) needs to be a child of user/%user and the tab link will then be created on "user/%user" and the child pages.

Create a custom token in Drupal 7

When wanting to add a url alias to the venue content type I ran into the problem that I was missing a token that I wanted to use. I wanted to add the city field of the location field in the venue content type to the url for Search Engine Optimization reasons. There is a token for the whole location field but it is not what I wanted, I just wanted the city field. The best solution here was to create a custom token for this field, so here are the steps I followed to create one. You first of all have to define your token in the hook_token_info():

Add breadcrumbs to a node in Drupal 7

By default Drupal adds breadcrumbs to the different pages on the site, of course you can remove this option but I think it's a very useful tool to help you navigate around the site. Once in a while the breadcrumbs aren't logical or aren't exactly what you want and this was the case for our blog nodes.

Outputting a block programmatically in Drupal 7

As a Drupal Developer chances are high that you have come across this same problem as me: you need to output a specific block in a certain place with special conditions and Blocks just doesn't give you the flexibility you need. First of all, if Blocks doesn't work try Contexts, a very powerful module which allows you to manage contextual conditions and reactions for different portions of your site, like place a block in a certain region under certain conditions.

How to create an Ajax Autocomplete field in Drupal 7

An AJAX field allows the user to type data into a text filed and dynamically display a list of matching options from which the user can choose from. This field is also called autocomplete or autosuggest. AJAX fields are a must in a site that has many forms. In Drupal we can use the very useful References module but it only allows you to refer to node of a content type.

Add a variable to theme template files in Drupal 7

The theme files (located in your theme directory and that have the extension .tpl.php) have access to variables which will come in handy for printing info out. What happens if the info you want is not access in the available variable? This is where the preprocess functions comes in handy, these functions are mainly used to add variables which can be used in the template files.

Create a custom field formatter in Drupal 7

Field formatters are used to render CCK fields in node views. Drupal provides default formatters. To customize the output of a field and have it apply it to multiple fields of the same type, a custom formatter needs to be created. 

The following tutorial is an example of how to add a formatter to the field of type link. To start look at the default formatters available for the link field in a Content Type. In Drupal 7 the available formatters for a field are found by going to Structure > Content types > The content type > Manage display. 

Create a block view with proximity filter in Drupal 7

The latest add on to our site has been the proximity filter. It's basically a view block on the venue page showing close by venues as can be seen on the image below. 

This tutorial shows step by step how to create a block view for node pages that displays other nodes that are in a defined distance range. 

Load content depending on the device using an ajax call in Drupal 7

This tutorial explains how to load "device specific content" depending on the device being used.

For this example the content being used are two embed views, one is called "Mobile embed" and the other is called "Desktop embed". To see how to create an embed view please go to the previous tutorial: Embeding a view in Drupal 7

Subscribe to