18.10.2016 Views

Drupal 7 Module Development

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 1<br />

<strong>Drupal</strong> core is the foundational layer of <strong>Drupal</strong> which ships with a handful of core<br />

libraries along with over a dozen core modules. The index file loads the libraries<br />

and then initializes <strong>Drupal</strong>, a process called bootstrapping.<br />

<strong>Drupal</strong> core libraries<br />

The core libraries provide the functions and services used throughout <strong>Drupal</strong>.<br />

Facilities for interacting with the database, translating between languages, sanitizing<br />

user data, building forms, and encoding data are all found in <strong>Drupal</strong>'s core libraries.<br />

These tools are what we might call utilities: They facilitate effective data processing,<br />

but are not responsible for handling the lifecycle of a request. The lifecycle is handled<br />

by modules.<br />

Once <strong>Drupal</strong> has loaded core libraries and initialized the database, it loads the<br />

enabled modules and themes, and then it begins a systematic, step-by-step process<br />

of handling the request. This process is what I call the lifecycle of a request. It works<br />

as follows.<br />

<strong>Drupal</strong> steps through a number of pre-determined operations. It checks to see if any<br />

modules need to be initialized. It looks up what code is responsible for handling the<br />

given URL. It checks whether the current user has access to the requested resource. It<br />

checks to see if some data can be retrieved from cache. It continues stepping through<br />

such operations until the request is complete.<br />

However, the most important thing about this step-by-step process is the way<br />

<strong>Drupal</strong> does it.<br />

<strong>Drupal</strong> hooks<br />

The <strong>Drupal</strong> core doesn't attempt to do the processing for each of these steps. Instead,<br />

after each step, it offers one or more modules the opportunity to handle that step. Put in<br />

<strong>Drupal</strong> parlance, it offers opportunities for modules to hook into the lifecycle.<br />

[ 13 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!