From Drupal 7 to Drupal 8
theme() functions to Twig templates
All of the
theme() functions are deprecated in Drupal 8. They are all converted into twig template files.
ALL GONE: All of the
theme()functions have been converted to Twig templates.
Removing the template process layer
- Remove the process layer (hook_process and hook_process_HOOK)
- The template process layer has been removed
The process layer was created to flatten complicated data structures - such as objects or arrays - into strings. In practice, render arrays themselves allow for late rendering via theme function or template file (and can be manipulated in other preprocess functions), and objects can implement
__toString methods for printing. There is no longer a need for this whole extra layer of processing before rendering.
Since the process layer got removed, the only layer between the data and the template is the preprocess layer.
The preprocess layer
The preprocess layer still exists, but it's used for a different purpose. In Drupal 8, the preprocess layer should not be used to add css classes. This should be done in the template files.
In Drupal 8, everything is a render array. This allows for late rendering, and allows data alterations to happen right before the template is being rendered.