Module Development

By shane
2012-10-01 23:54
8 comments
Daily Dose of Drupal Episode #19

This continues on the module we started last time and shows how to implement hook_cron to run periodic tasks on your Drupal website. Also goes over hook_mail and the drupal_mail function for creating and sending email messages within your Drupal 7 module.

In this episode you will learn:

  • How to implement hook_cron in a Drupal 7 module
  • How to implement hook_mail to set up email messages in your Drupal 7 module
  • How to trigger the sending of email in a Drupal 7 module with the drupal_mail function
By shane
2012-09-28 13:02
5 comments
Daily Dose of Drupal Episode #18

Learn how to create an administration form inside a Drupal module. In this episode we work with the Drupal 7 Form API to build out an administration section for a brand new module. This new module (called cronmonitor) will be completed in the next Daily Dose of Drupal episode (number 19).

In this episode you will learn:

  • How to build a Drupal administration form inside a Drupal 7 module
  • How to set the configure option inside your modules .info file
  • How to implement hook_menu and hook_permission to create an administration page
By shane
2012-09-27 23:50
2 comments
Daily Dose of Drupal Episode #17

In this episode we continue learning about Drupal 7 module development by looking at creating menu items with hook_menu() and creating permissions with hook_permission().

In this episode you will learn:

  • How to implement hook_menu() in you Drupal 7 module to create a new page on your Drupal site
  • How to implement hook_permission() in your Drupal 7 module to provide access control to your newly created page
By shane
2012-09-26 23:16
0 comments
Daily Dose of Drupal Episode #16

In this episode you will learn the very basics of Drupal 7 module development. From the info file, Drupal hooks, and the module file, this is a crash course to get you started.

In this episode you will learn:

  • How to create a very simple Drupal 7 module
  • How to create a Drupal 7 module .info file
  • How to create the main .module file
  • The importance of Drupal hooks and how they can be used to interact with the Drupal API
  • How to create a custom block inside your created Drupal 7 module using hook_block_info() and hook_block_view()
By shane
2012-09-26 17:12
4 comments

If you need to make price increases when specific attributes or options are selected on products, hook_cart_item() may be able to help you out.

My Drupal 6 Ubercart Dilemma

In a recent situation I needed to create an attribute that contained a price. The trick here is that the price increase needed to be added based on the value selected in another corresponding attribute.

By shane
2012-09-07 17:18
6 comments

Ever need to output a Drupal 7 view in your code? If so the views_embed_view function is an easy way to do this. One thing you may not have known, is that you can also use it to pass values into your views contextual filters (what the Drupal views module used to call "arguments").

Here is a quick example of how to output a view in code using the views_embed_view function:

print views_embed_view('VIEWS_MACHINE_NAME', 'DISPLAY_ID');
By shane
2012-09-06 15:11
1 comment
Daily Dose of Drupal Episode #2

Daily Dose of Drupal episode 2 looks at the Drupal 7 Features module and how it can be used to easily deploy common configurations across multiple Drupal sites.

Code Karate's 5 Secrets to Becoming a Drupal 7 Ninja ebook contains a complete Introduction to the Drupal Features Module.

By shane
2012-04-30 10:10
18 comments

I often get asked what is the best way to go about learning Drupal or the best way to get started with website development. Because of these questions, I decided to put together a list of things I wish I would have done first, when I started to teach myself Drupal.

By shane
2011-09-01 09:16
3 comments

I recently wanted to create a comment system that was threaded but only allowed one level of replies. Basically I wanted something like this:


-Comment 1
---Reply 1-1
---Reply 1-2
-Comment 2
---Reply 2-1
---Reply 2-2

I still wanted to show all the reply links in the comment, however if a user tried to reply to an already indented comment, I wanted it to just add it to the bottom of the thread. For instance, clicking the reply link on "Reply 1-1" in the example above would add a "Reply 1-3" comment directly below "Reply-1.2". Make sense?

By shane
2011-08-24 09:55
3 comments

When using the traditional Ubercart catalog module, I have run into the problem of needing to classify and display products in multiple catalogs. You would think I could just create a block of the taxonomy terms, however that will create links to the taxonomy term pages and the display for that is vastly different than the catalog display.

Here is my quick solution. I basically create another catalog block. This will open up the products in my secondary taxonomy vocabulary (that I am using as an additional catalog), using the traditional Ubercart catalog layout/design.

By shane
2011-08-18 14:43
1 comment

For most form submissions on a Drupal site you will want some form of spam prevention. While I generally use the Mollom module for most of my spam prevention, occasionally it is more than I need. For instance, lets say you have a really simple newsletter signup form and you want to prevent the majority of spam but do not want to inconvenience your users with trying to read and enter in the value of a cryptic looking captcha just to sign up. The easiest solution is to implement a hidden field.

By shane
2011-08-16 21:43
0 comments

I have seen many different methods to remove the "Search this site" text that sits in the Search block in Drupal 6. Because there are so many different approaches I wanted to show the way that I use in almost every site I build that contains a search block. The simplest way to remove the text is using CSS, however if you want to prevent it from showing up in the HTML markup completely just add this to a custom module (replacing MYMODULE with your module name):

By shane
2011-08-15 22:55
4 comments

Here are some quick code examples that I have used to add or remove user roles in Drupal 6. This can be very helpful if you are building a module for a specific site that has to manipulate user roles. Using this technique is not the most flexible solution as it limits itself to the roles configured on a specific site (based on role id and role name). However, you could easily add a database table and an administration section and make this more flexible if needed.

Here is an easy way to add a role:

By shane
2011-08-11 13:37
1 comment

In the past at BEgINr Media, we used a heavily modified version of Open Atrium (a Drupal Distribution) for project management. One of the additions we added on our version of Open Atrium is the CaseTracker Plus Drupal Features module. This Drupal module uses the Driven API and Comment Driven modules to allow changes to the tasks while posting comments.

By shane
2011-03-16 00:03
1 comment

I recently had a small issue where my Drupal 6 node object did not have all the current and correct data because the node that was stored in the Drupal node cache was out of date. This is not something I have run into very often (I think only one other time before tonight), however if you run into the same problem then here is the solution:

Rather than just using:

By shane
2011-03-15 08:26
0 comments

As mentioned in a previous post, here is a quick shortened and simplified example that is similar to the code I used on a past Drupal site to create a message template. This example uses the messaging modules hook_messaging, it also declares a few token values that are passed through to the template.

Subscribe to Module Development