The Webform API allows us to create custom components via Webform extension modules. We may be tempted to create our custom component within the existing sites/all/modules/webform/components
folder, but that is tantamount to hacking Webform core and will create a maintenance headache for us in the future. Let's get the ball rolling and get our extension module properly set up.
Explanatory details on the steps that follow can be found in the recipe Changing Webform results defaults discussed in Chapter 3, Working with Submissions, and Defining custom option lists discussed in Chapter 6, Extending Webform, and in Chapter 8, Acting on Webform Submissions, where we created modules to extend Webform and Webform Validation. Those of us who have completed the exercises in these chapters will recognize the pattern of effort.
webform_imei
in sites/all/modules
so that we have the folder path sites/all/modules/webform_imei
. webform_imei.info
into the sites/all/modules/webform_imei
folder we just created. Edit the file to add the following text and save the changes:name = Webform IMEI Custom Component description = Adds an IMEI number component to Webform core = 7.x dependencies[] = webform package = Webform
webform_imei.module
in our new module folder. We add the following lines of code to our module file and save the changes:<?php /** * @file * Webform International Mobile Equipment Identity (IMEI) Custom Component. */
This last file, webform_imei.module
, is where we will place all the code from the sections that make up the remainder of this chapter.
Every extension module is given its very own folder in /sites/all/modules
. Within this folder we need, at a minimum, a module_name.info
file (which describes the module to Drupal) and the programming that does the actual work of the module, which is placed in the module_name.module
file. For a full introduction to creating Drupal 7 modules, we may pay a visit to http://drupal.org/node/361112.