Drupal 7 Module Development

A complete guide to practically building a fully functional custom Drupal 7 module from scratch.
3.7 (17 ratings)
Instead of using a simple lifetime average, Udemy calculates a
course's star rating by considering a number of different factors
such as the number of ratings, the age of ratings, and the
likelihood of fraudulent ratings.
237 students enrolled
Take This Course
  • Lectures 43
  • Length 3 hours
  • Skill Level All Levels
  • Languages English
  • Includes Lifetime access
    30 day money back guarantee!
    Available on iOS and Android
    Certificate of Completion
Wishlisted Wishlist

How taking a course works


Find online courses made by experts from around the world.


Take your courses with you and learn anywhere, anytime.


Learn and practice real-world skills and achieve your goals.

About This Course

Published 12/2014 English

Course Description

In this course you will learn to build a Drupal custom module by completing short tasks and ultimately weave the tasks together to get a completed and fully functional module. Drupal 7 Module Development introduces you to module development by understanding the essential hooks and functions, building tables and querying the Drupal database, exploring module security, performance and how our module interacts with Drupal core and contributed modules. Each video walks you through essential Drupal functions and demonstrates how to use these functions in a module that we build hands-on together Drupal 7 Module Development starts by showing you how to set up your local development environment to support custom module development. You will learn how to use the best tools and configure them. Next you will learn to configure a Feeds importer to import content into your site that you will then leverage with your custom module and write a menu callback using hook_menu and hook_permissions. We will then look at the form API and write a hook_form_alter function and create a .install file and build a db schema function to create a table in our database Finally we create a block using our module and theme the block. We end the course by reviewing our module from a security and performance standpoint. From the local development to the review of security we build a custom module step-by-step throughout the course’s short videos.

About the Author

Trevor James is a Drupal developer residing in Middletown, MD, USA. Trevor has been using Drupal intensively since 2007 and designing websites for over 15 years using a combination of HTML, CSS, ColdFusion, PHP, jQuery, and JavaScript.

Trevor's focus is on building Drupal-based web applications and portals for education, non-profit, and medical systems, and small business environments. He is interested in the best methods of integrating web services with Drupal sites, optimizing Drupal sites' performance, and using Drupal content types, Views, Panels, and other contributed modules to develop front-end interfaces that support data intensive websites.

He loves teaching people about Drupal and how to use this excellent open source content management framework.

What are the requirements?

  • You should have a familiarity with Drupal but no experience with programming Drupal custom modules or PHP is required to follow this course.
  • All videos include hands-on practical examples to follow along with. This course is geared towards beginners in Drupal development and anyone who wants to learn to use Drupal code.

What am I going to get from this course?

  • Build a .info and .module file to set up your module.
  • Write hook_menu and hook_permissions functions
  • Set up an admin settings form and use hook_form_alter
  • Create database tables using hook_schema and .install files
  • Write node hooks and database queries
  • Create a custom block via your module
  • Theme the block and write CSS to style it
  • Use t function and other sanitization functions to secure your module
  • Use and create custom Drupal variables
  • Explore the research functions in the Drupal API

Who is the target audience?

  • This course is perfect for any Drupal user who is just starting to explore Drupal core and contributed modules. If you’ve used some contributed modules you can now turn to learning how to write your own custom Drupal 7 module.

What you get with this course?

Not for you? No problem.
30 day money back guarantee.

Forever yours.
Lifetime access.

Learn on the go.
Desktop, iOS and Android.

Get rewarded.
Certificate of completion.


Section 1: Installing Drupal for Custom Module Development

We need to set up a local development environment for our Drupal programming. Install an Apache Web server locally with PHP and MySQL to support a Drupal 7 website.


Install a local integrated development environment that we'll use to code our custom Drupal module.


Set up a local Drupal 7 website install. Download Drupal 7.14 and install Drupal core.


Enable a few core Drupal 7 modules and inspect the /modules directory.


Learn how to set up folders to hold the contributed and custom Drupal module we'll be working on in this video series.

Section 2: Introducing the Custom Facebook Feed Module

We've installed the Feeds module but we need to install the required and dependent modules so we can enable all of the Feeds suite of modules and configure a Feeds importer. We install the Ctools and Job Scheduler modules; as well as the Views, Devel and Feeds Tamper modules. We also load our Facebook page's RSS feed and get the RSS feed URL to use in our import process.


To import our RSS feed we need to clone an existing Feeds importer that handles XML and RSS feed parsing. Once the importer is created we can run our import by adding the RSS feed. The import will create nodes on our site using the Feeds Item content type.


Our PHP memory limit is at 32M but we'll need more memory to run the Feeds, Devel, and Feeds Tamper modules and run our import. We raise the memory limit to 96M. We also set up a tamper on our importer to change importer characters to specific apostrophes.


We need to be comfortable using PHP when we code our module so that we can point out some PHP resources for Drupal developers. We also look at some documentation on Drupal coding standards and inspect some contrib module code to see how these standards are applied.


The first custom module file we need to create is the .info file. We create the .info file and write some code into it. We also create a .module file. We then enable our new custom module.


We'll add some PHP code and comments to our module file and practice Drupal coding standards for commenting.


We need to know what functions are available to us when we write our module code so that we can review the api.drupal.org website.


We need to use the Devel module so we can have access to tools and utilities for Drupal developers.


How can we access specific content type field names and other data about our nodes? Using the Devel module enables us to inspect all of our page elements.

Section 3: Menu Callbacks and Permissions

Now that we have our .info file and .module file created we need to start writing functions for our module. The first function we'll write is called hook_menu. This function will allow us to create an array(s) for each of our module's admin screen menu items. This way our module's users can configure the module via the Drupal admin interface.


If you do not see your hook_menu function working yet you need to flush the Drupal cache.


Now that we have a function in our module and the module is working, we need to add some permissions so our roles can use the module. We do this by writing a hook_permission function.


Now we need to add the admin.inc file to our module folder so we can start writing our menu callback functionality including the drupal_get_form function we added earlier to our .module file.

Section 4: The Form API

We have a blank admin.inc file that we need to add our admin_settings_form function to in order to build out the admin settings form for our module. We add the function to our admin.inc file and all form elements including a text field and checkbox series to it.


We've added a text field to our admin form. Now we expand our form by adding a checkbox series to allow for choosing the content types that our module will integrate with


We review how our module is setting and getting variables defined on our admin settings form.


Our text field needs a couple of validation handlers. We write these using hook_validate.


We need to allow our admins to choose specific nodes to show in the Facebook Feed Block. To do this we need to alter the content type edit form to add an admin fieldset for our checkbox.

Section 5: Connecting with the Database

We are collecting data via our hook_form_alter on our node edit form but currently we have no way to save the data we collect. We need to define our database schema and create our db tables for our module. First we need to create the .install file.


We need to add our hook_schema function to the .install file to define our first db table and schema for our module.


We need to add the schema for our hook_form_alter data. We add another schema array to our .install file.


Every time we add a schema function to our .install file we also need to uninstall and reinstall our module for the new schema to work. We also need to clear out all variables that we're setting when we uninstall our module. We do this by adding the hook_uninstall function.


We can add more functions to our .install file to manage the install and updating process.

Section 6: Node Hooks and Database System

We need to allow our module to modify a node when the user uses the hook_form_alter, so we need to add node hooks to allow us to modify the nodes that we have enabled for use with our module.


We continue to add node hooks to allow for updating and deleting any modifications that we've made to our nodes.


We still need to add our values set using our hook_form_alter to our database table. To do this we'll write some database wrapper functions that will query the db.


We add additional db queries to help with deleting data


We need to learn how to make our database query code as secure as possible and we look at some Drupal best practices for doing this.

Section 7: Block System and Theming

We add a hook_block_info function that makes Drupal aware of our custom Facebook Feeds block.


We need to show content in our custom block so we add a hook_block_view function that will define our block contents.


We need to use a database query in order to display our Facebook posts inside the custom block.


Now that we have a block showing content we need to theme it with the custom style.


We have our custom code and <div> printing in our custom theme template. Now we need to add some custom style.

Section 8: Security, Performance, and Testing of our Module

We need to write secure code throughout our module project life cycle so in this video we look at the various documentation that the Drupal API provides to help us write secure code.


We install and configure the Coder module to run automatic reviews of our contrib, core, and custom module code.


We need a system for running automatic tests of our custom module. We enable and configure the Testing module for this.


We now need to write a custom .test file and add this to our module.


We now need to enable our .test file via the Testing module and run our automated test.

Students Who Viewed This Course Also Viewed

  • Loading
  • Loading
  • Loading

Instructor Biography

Packt Publishing, Tech Knowledge in Motion

Over the past ten years Packt Publishing has developed an extensive catalogue of over 2000 books, e-books and video courses aimed at keeping IT professionals ahead of the technology curve. From new takes on established technologies through to the latest guides on emerging platforms, topics and trends – Packt's focus has always been on giving our customers the working knowledge they need to get the job done. Our Udemy courses continue this tradition, bringing you comprehensive yet concise video courses straight from the experts.

Ready to start learning?
Take This Course