Best Practices for Creating Persistent Variables in Drupal 7


show more Exploring best practices with variable persistence provides you with in-depth training on Developer. Taught by Jon Peck as part of the Drupal 7 Custom Module Development show less
please wait ...

Exploring best practices with variable persistence

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...

Exploring best practices with variable persistence
Video duration: 9m 29s 2h 56m Advanced

Viewers:

Exploring best practices with variable persistence provides you with in-depth training on Developer. Taught by Jon Peck as part of the Drupal 7 Custom Module Development

Subjects:
Developer Web
Software:
Drupal
Author:
please wait ...