I'm trying to use the ThemeNegotiator to change the theme of the add and edit pages of one content type. I've followed the following very extensive posts/blogs.
Don't use admin theme for adding editing specific content type
Dynamic theme switching in Drupal 8
Soft launching your new drupal theme
Choose your theme dynamically Drupal 8
I have a user that is allowed to see the Admin theme seven
, but for one content type documenten
I want him to see the front-end theme svds
. I'm able to get this to work for front-end pages but not for admin pages. What I think is that the applies
part doesn't match on the add and edit pages. So it doesn't know it's on a documenten
content type. Does anyone has an idea on how to solve this?
Module structure:
theme_switcher
--src
----Theme
------SwitcherNegotiator.php
--theme_switcher.info.yml
--theme_switcher.services.yml
theme_switcher.info.yml:
name: Theme Switcher
type: module
description: 'Switch theme for specific Content Type'
package: SVDS
core: 8.x
theme_switcher.services.yml:
services:
theme.negotiator.theme_switcher:
class: Drupal\theme_switcher\Theme\SwitcherNegotiator
tags:
- { name: theme_negotiator, priority: -50 }
SwitcherNegotiator.php:
<?php
/**
* @file
* Contains \Drupal\theme_switcher\Theme\SwitcherNegotiator
*/
namespace Drupal\theme_switcher\Theme;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Theme\ThemeNegotiatorInterface;
class SwitcherNegotiator implements ThemeNegotiatorInterface
{
/**
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $route_match)
{
// Use this theme on a certain route.
$node = $route_match->getParameter('node');
if (!is_null($node) && $node instanceof \Drupal\node\Entity\Node) {
return $node->getType() == 'documenten';
}
// apply default theme
return false;
}
/**
* {@inheritdoc}
*/
public function determineActiveTheme(RouteMatchInterface $route_match)
{
// Here you return the actual theme name.
return 'svds';
}
}