Drupal 7 custom module boilerplate
Full featured custom module boilerplate with already setup structure and default functionality. The module and all example code is built completely using Drupal best practices and standards.
See the version for Drupal 8 here.
- Custom forms, validation and submit handlers
- Batch jobs
- Cron integration
- Token integration
- Skinr integration
- Rules integration
- Drush integration
- Node and user tabs integration
- Webform field implementation
- Theme/template implementation
- Separation of module code in appropriate files (
.pages
,.tokens
,.forms
,.admin
,.batch
) - Email implementation, including both - text only (default) and rich (HTML) emails
- Custom helper functions for:
- Generating a random string of arbitrary length
- Get the list of all image styles on the site
*
- Get the list of all nodes on the site
*
- Get the list of all node types on the site
*
- Get the list of all users on the site
*
- Get the list of all roles on the site
*
- Get the list of all vocabularies on the site
*
- Check if a user has a specific role
- Check if a request is an AJAX request. Useful when overriding tricky form elements, e.g. setting a default value on Addressfield on checkout page with Commerce.
- Secure string comparison from HTTP Auth library of Zend Framework
*
Admin form friendly - means you can use this output directly in select boxes or radio fields in admin forms.
Most bigger websites will have a main custom module, with general system modifications or general features and additional custom modules focused on a particular functionality. This boilerplate is suitable for creating that main module.
Few different ways:
- Copy/paste the parts you need in your custom module.
- Clone the whole repo and make the following replacements:
- Rename all
boilerplate.
files toYOUR_MODULE.
. - Replace all
boilerplate
(lowercase) words withYOUR_MODULE
(lowercase as well). - Replace all
BOILERPLATE
(uppercase) words withYOUR_MODULE
(uppercase as well). - Replace all
Boilerplate
(capitalized) words withYOUR_MODULE
(capitalized as well). - Customize the code to fit your project.
- Rename all
Not all projects will need every component that is included in this module. Below are instructions on how to remove those parts. If you want to do this after you have installed the module, don't forget to clear all caches after removing the components.
- open
boilerplate.module
file and remove theboilerplate_menu()
function - open
boilerplate.info
file and remove the following line:configure = admin/config/boilerplate/settings
- remove or empty the
boilerplate.forms.inc
file - remove or empty the
boilerplate.pages.inc
file - remove or empty the
boilerplate.admin.inc
file - remove or empty the
boilerplate.batch.inc
file
- open
boilerplate.module
and remove theboilerplate_theme()
function - remove the
/theme
directory
- open
boilerplate.module
file and remove the following line:require_once dirname(__FILE__) . '/boilerplate.mailsystem.inc';
- remove the
boilerplate.mailsystem.inc
file
- open
boilerplate.module
file and remove the following line:require_once dirname(__FILE__) . '/boilerplate.helpers.inc';
- remove the
boilerplate.helpers.inc
file
- open
boilerplate.info
file and remove the following line:files[] = boilerplate.test
- remove the
boilerplate.test
file
- open
boilerplate.module
file and remove theboilerplate_views_api()
function - remove the
/views
directory
- remove the
boilerplate.tokens.inc
file
- remove the
boilerplate.rules.inc
file
- remove the
boilerplate.drush.inc
file
- open
boilerplate.module
and remove theboilerplate_skinr_api_2()
function - remove the
/skins
directory
By: topsitemakers.com.