- πΊπΈUnited States dave.gutierrez0@gmail.com Florida
Thanks very much @steven-snedker. I found this useful for overriding Theme Switcher rules for a given content type only if the node is associated with a given taxonomy term. Here's what I ended up with as a variation of what you did that only switches the theme for 'View' mode for a given node:
/modules/custom/custom_module/src/Theme/ThemeNegotiator.php
/** * @file * Contains \Drupal\custom_module\Theme\ThemeNegotiator */ namespace Drupal\custom_module\Theme; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Theme\ThemeNegotiatorInterface; class ThemeNegotiator implements ThemeNegotiatorInterface { /** * @param RouteMatchInterface $route_match * @return bool */ public function applies(RouteMatchInterface $route_match) { return $this->negotiateRoute($route_match) ? true : false; } /** * @param RouteMatchInterface $route_match * @return null|string */ public function determineActiveTheme(RouteMatchInterface $route_match) { return $this->negotiateRoute($route_match) ?: null; } /** * Function that does all of the work in selecting a theme * @param RouteMatchInterface $route_match * @return bool|string */ private function negotiateRoute(RouteMatchInterface $route_match) { $node = $route_match->getParameter('node'); // Check if the current route is the node canonical view (i.e., viewing the node) if (!empty($node) && $route_match->getRouteName() === 'entity.node.canonical') { // Ensure we have a node and it's of the type 'content_type' if (!empty($node) && $node->getType() == 'content_type') { // Check if the node has a 'field_template' field and it's not empty if ($node->hasField('field_template') && !$node->get('field_template')->isEmpty()) { // Apply the 'theme_to_switch_to' theme return 'theme_to_switch_to'; } } } return false; } }
- π§πͺBelgium tim-diels Belgium π§πͺ
You should look at Entity field condition β as that provides this condition out of the box for you for nodes. It would be fairly easy to look how this is done and do this yourself for taxonomy and provide a feature request there. Maybe this can be added as documentation and this can be closed as works as designed?