Drupal 8/9: Theme negotiation based on condition plugins

Case type:

Service area: 

Technologies:

Sooner, the European Commission Drupal [project I'm working on](https://joinup.ec.europa.eu/), will transition to a new theme. During the transition, some pages will be still displayed using the the old theme. I've looked around for a Drupal module that knows to render a certain page using a specific theme and found [Switch Page Theme](https://www.drupal.org/project/switch_page_theme). The big impediment with this module is that it mainly checks the page path. And this is more or less hardcoded. There's no way to add arbitrary conditions, such as a [route condition](https://www.drupal.org/project/route_condition), which is the one I'm more interesting in.

As proposing a change to the existing module would have been a too disruptive and hard to address in terms of backwards compatibility issues, I've built the [Theme Negotiation by Rules](https://www.drupal.org/project/theme_rule) module, which has and open architecture, allowing third-party modules to hook in by providing condition plugins. The _Theme Negotiation by Rules_ module allows a site builder to show pages using different themes based on rules. Each rule contains the theme, and the conditions to be met in order to show the that theme. Conditions are [condition plugins](https://www.drupal.org/node/1961370), such as page path pattern, current user role, current language or, even, the type of the node, when the page is a node canonical page.

As my theme selection is mainly based on routes, all I have to do is to install [Route Condition](https://www.drupal.org/project/route_condition) and [Theme Negotiation by Rules](https://www.drupal.org/project/theme_rule) modules and to use the UI to define my theme rules.