Join Jon Peck for an in-depth discussion in this video Exploring best practices with variable persistence, part of Drupal 7: Custom Module Development.
In the previous video, I used variable_get with a default value to populate the form …with sensible defaults. …This works quite well when the form is submitted, but what happens if functionality that requires …those variables is triggered? …They just won't be there unless I use a variable_get that also has default values. …That doesn't scale well however. …What if I want to use that variable in a dozen places? Then I have to define a default value …a dozen times. Then if I ever change the default then I have to re-factor all those places, and so forth.…
That approach doesn't scale well. …Instead, I will leverage a one-time triggered event when a module is installed to set the …defaults in one place using hook_install. …Return to the IDE. …By convention, hook_install is always placed in its own file named module name.install. …Therefore for the windfarms module I will create a New > Empty File called windfarms.install, …windfarms.install. …Install files are just PHP scripts, so I will start the file with an open PHP tag and a …
- Creating your first module
- Interacting with hooks
- Working with permissions and roles
- Controlling access
- Adding a menu item to an admin interface
- Using the Form API (FAPI) to quickly create a form
- Creating custom form validation
- Manually creating a custom content type
- Validating user input
- Importing content using feeds
- Creating a block
- Understanding best practices and coding standards
Skill Level Advanced
Q: gmap3_tools is not working the way I expected it to. What version of gmap3_tools should I be using?
A: Use the free exercise file containing the version of gmap3_tools used for recording; the published version of the module on drupal.org has changed since recording and is not backwards compatible.
Q: I attempted to run the Drupal site root from the project files, but the site isn't loading. Why not?
A: The Drupal configuration file in sites/default/settings.php contains database configuration specific to the environment used to record the movie. This may be different than your environment. Edit the file and search for "windfarms" - you may need to change the database host, username, password, db name and port to match your specific environment.