Design-Safe Theming in Drupal: Make Impossible States Impossible
Gizra’s Amitai Burstein advocates for applying the “Make Impossible States Impossible” principle—common in functional programming—to Drupal theming workflows, helping developers encode intent instead of loose implementation details.
Originally rooted in typed languages like Elm and Haskell, the principle of making invalid states unrepresentable can also guide logic in PHP and Twig. Burstein demonstrates how using PHP Enums and structured traits in Drupal theming can prevent scenarios where designs deviate due to excessive flexibility. For instance, instead of passing arbitrary border widths and colors into templates, developers can define BorderTypeEnum values like HeroImage or Paragraph, and let the Twig layer decide styling based on that intent.
The article outlines how this pattern aligns with design systems and prevents gradual visual inconsistency across sites. Leveraging modules like Pluggable Entity View Builder (PEVB) and “Theme Traits,” the approach helps tame the ever-expanding combinations of presentation logic. Though Drupal and PHP aren’t strictly typed, Burstein argues that applying structured thinking drawn from typed functional languages leads to better, more maintainable theming decisions.


