Check your version

This video covers a topic in Drupal 7 which may or may not be the version you're using. We're keeping this tutorial online as a courtesy to users of Drupal 7, but we consider it archived.

Alternate resources: 

Introduction to Module Development for Drupal 7

Video loading...

  • 0:07
    Introduction to Module Development for Drupal 7 Joe Shindelar
  • 0:16
    If you've been around Drupal for a little while,
  • 0:18
    you've probably heard the phrase, there's a module for that.
  • 0:22
    And with over 9,000 modules currently on drupal.org,
  • 0:25
    there's a good chance it's true,
  • 0:26
    there's probably a module that does at least some of what you need already.
  • 0:30
    But what if there isn't
  • 0:31
    or what if that module doesn't quite do what you need it to do
  • 0:34
    and you need it to do something slightly different or in a slightly different way?
  • 0:39
    In this video series, we'll be taking an in-depth look at
  • 0:42
    creating modules for Drupal 7
  • 0:44
    and covering many of the major components and concepts, APIs, and resources
  • 0:48
    that will help you become a module developing rock star.
  • 0:52
    Throughout the course of this video, we'll build a handful of simple modules
  • 0:55
    that demonstrate the use of Drupal's APIs.
  • 0:58
    We'll take a look at Drupal's documentation
  • 1:00
    and where to find information about
  • 1:02
    what's going on under the hood in Drupal
  • 1:04
    and the APIs that are available to you
  • 1:06
    both on drupal.org and on api.drupal.org.
  • 1:11
    In addition to that, we'll take a look at a module called Devel,
  • 1:14
    which will help us inspect the code inside of our own modules
  • 1:18
    and get a better idea of the variables, functions
  • 1:21
    and the way that things are working under the hood in Drupal.
  • 1:24
    And then we'll take a look at integrating with Drupal's Hooks system,
  • 1:28
    the mechanism that allows us as module developers
  • 1:32
    to respond to different events and questions that Drupal asks,
  • 1:36
    basically, allowing us to alter the way that Drupal behaves
  • 1:39
    or add additional functionality to Drupal core
  • 1:41
    or some of the third-party modules, without having to hack core
  • 1:45
    or any of the code from someone else's module.
  • 1:49
    In addition to looking at Drupal's Hooks system,
  • 1:51
    we'll also take a look at the API provided by Drupal.
  • 1:55
    One of those is a bunch of functions that will help us write more secure code.
  • 1:58
    In addition to looking at those functions,
  • 2:00
    we'll also talk about what it takes to write secure code.
  • 2:03
    How to make sure that you're preventing people
  • 2:05
    from exploiting your site using cross-site-scripting attacks
  • 2:08
    or cross-site-request forgeries.
  • 2:10
    Or if you're querying the database,
  • 2:11
    how to make sure that you're preventing SQL injection.
  • 2:15
    We'll cover writing secure code pretty early on in the series,
  • 2:18
    getting it out of the way so that we can make sure
  • 2:20
    that as we write code for the rest of the videos in the series,
  • 2:23
    we're doing so in a secure format.
  • 2:25
    After getting some basic explanations out of the way,
  • 2:28
    like what is a hook and how do we write secure code,
  • 2:31
    we'll take a look at the anatomy of a module.
  • 2:33
    Where does our code go within the Drupal system?
  • 2:36
    How do we name our files so that Drupal knows how to find them?
  • 2:39
    What the heck is a .info file?
  • 2:41
    What are these .module files?
  • 2:43
    And get an idea for all the different components that make up any module in Drupal.
  • 2:48
    Once we've got those basics out of the way,
  • 2:50
    we'll take a look at implementing hook_menu
  • 2:52
    so that our modules can create new pages on our Drupal site
  • 2:55
    that live at a specific URL.
  • 2:58
    We'll start with the very basics
  • 2:59
    and then work on some of the more complicated aspects of hook_ menu
  • 3:02
    like controlling permissions, wild cards in your URL,
  • 3:06
    and a concept that Drupal calls autoloader functions.
  • 3:10
    While we're going through the menu system,
  • 3:11
    we'll also learn about ways that your module can build and create content
  • 3:15
    and then return it to Drupal in an appropriate format,
  • 3:18
    a system that Drupal refers to as renderable arrays or the Render API.
  • 3:24
    Once we've got content that we're returning to a page
  • 3:27
    or any portion of our Drupal site,
  • 3:29
    we'll also need to make sure that we're returning it in a themeable way.
  • 3:32
    So we'll take a look at how we as module developers can use tools
  • 3:36
    like Drupal's hook_theme and built-in themeing functions,
  • 3:40
    in order to make sure that any HTML that we create inside of our module
  • 3:44
    can be overridden at the theme layer.
  • 3:46
    You never know what those designers might want to do with our HTML,
  • 3:49
    but we want to make sure that they don't have to hack our module
  • 3:52
    in order to make those changes.
  • 3:54
    Then with renderable arrays and themeing out of the way,
  • 3:57
    we'll take a look at Drupal's Form API,
  • 3:59
    which is sort of an extension of the Render API system
  • 4:02
    that allows us to build forms with built-in security and a built-in workflow
  • 4:07
    for validating and submitting the data from those forms.
  • 4:11
    In addition to looking at the built-in workflow for forms
  • 4:14
    and how to build a simple form,
  • 4:15
    we'll look at a few more of the complex things that you can do with forms
  • 4:18
    like the new #states system in Drupal 7,
  • 4:22
    which allows us to create forms that are not only functional but pretty as well.
  • 4:26
    We'll also take a look at
  • 4:28
    using Drupal's new database abstraction layer or DBTNG.
  • 4:33
    In order to query the database, to pull in information,
  • 4:37
    update information in the database,
  • 4:39
    delete information in the database,
  • 4:41
    how our module can create its own schema in the corresponding tables.
  • 4:45
    We'll even get into how after a module has already been deployed on a site
  • 4:49
    and the table has been created,
  • 4:51
    we can update the schema for our module as we go.
  • 4:55
    And then finally, we'll end the series
  • 4:57
    with a discussion of some best practices, tips and tricks
  • 4:59
    for keeping your code organized, maintainable,
  • 5:02
    and when possible, contributing it back to drupal.org.
  • 5:06
    So now that you know what we're going to cover in the series,
  • 5:09
    let's fire up our text editor IDE and get started creating some code.

Introduction to Module Development for Drupal 7

Loading...

"There's a module for that."

You've probably heard this before. Many times you can find a module that provides the functionality you need — or at least pretty close to what you need. Drupal's contributed module projects number in the thousands, but what if there isn't a module for your use case? You just might need to build a module for that.

In this series, you will learn about the tools and resources available to Drupal developers, including where to find documentation and what APIs are available to you, both on drupal.org and api.drupal.org. We'll take a look at the Devel module and learn how to use it to inspect the variables, objects, arrays and other things at work under the hood of Drupal 7.

You'll build several different modules that explore and interact with Drupal's various systems and API, including:

  • Form API
  • Menu system
  • Hooks
  • Render API
  • Theme system
  • Database API

Over the course of this series you'll be able to:

  • Describe the anatomy of a module
  • Implement common hooks
  • Write more secure code
  • Interact with Drupal's menu system
  • Create and alter forms
  • Peform CRUD operations on a database

This series starts with the basics and moves you step-by-step to more advanced concepts. Even if you are quite comfortable with PHP but are struggling to understand how to appropriately interact with Drupal 7's API, the lessons in this series can help you develop "The Drupal Way."

Downloads: 
Log in or sign up to download companion files.
Additional resources: