Business logic versus presentation logic
We start this chapter by discussing an important architectural choice that modern applications make: how to turn data into presentation.
So, what would be the best way to get our data and functionality marked up? Do we simply wrap each piece of data in HTML and return the whole thing as a giant string, as shown in the following example?
return '<div class="wrapper">' . $data . '</div>';
No, we don’t. Like all other well-designed applications, Drupal separates its business logic from its presentation logic.
Traditionally, the primary motivations for this separation of concerns are as follows:
- To make the code easier to maintain
- To make it possible to easily swap out one layer’s implementation without having to rewrite the other layer
As we will see, Drupal takes the “swapability” aspect quite far. You may think that the theme you select on the...