In the course of developing our site, we will frequently come across situations where various elements of the site need to be tweaked in PHP using Drupal's APIs. While a lot of theme-specific cases can be stored in template files, certain tweaks which are theme-agnostic require that we store them in a module to ensure that they are available to all themes.
This recipe covers the creation of a module to hold our tweaks and other bits and pieces.
As we saw when creating the mytheme
subtheme earlier in this chapter, the sites/all
folder provides a modules
folder along with a themes
folder to hold our custom and contributed installations. These modules and themes are automatically made available to all sites using this Drupal installation. However, if we are looking to restrict the use of our module solely for a particular site, then we would place it within sites/foo.example.com/modules
instead.