Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
ThemeNegotiator | |
0.00% |
0 / 9 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
applies | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
determineActiveTheme | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace Drupal\crm\Theme; |
4 | |
5 | use Drupal\Core\Config\ConfigFactoryInterface; |
6 | use Drupal\Core\Routing\RouteMatchInterface; |
7 | use Drupal\Core\Theme\ThemeNegotiatorInterface; |
8 | |
9 | /** |
10 | * A negotiator for custom crm theme. |
11 | */ |
12 | class ThemeNegotiator implements ThemeNegotiatorInterface { |
13 | |
14 | /** |
15 | * The config factory. |
16 | * |
17 | * @var \Drupal\Core\Config\ConfigFactoryInterface |
18 | */ |
19 | protected $configFactory; |
20 | |
21 | /** |
22 | * Constructs a new ThemeNegotiator. |
23 | * |
24 | * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory |
25 | * The config factory. |
26 | */ |
27 | public function __construct(ConfigFactoryInterface $config_factory) { |
28 | $this->configFactory = $config_factory; |
29 | } |
30 | |
31 | /** |
32 | * {@inheritdoc} |
33 | */ |
34 | public function applies(RouteMatchInterface $route_match) { |
35 | if ($route_match->getRouteObject()) { |
36 | $path = $route_match->getRouteObject()->getPath(); |
37 | if (strpos($path, '/crm') === 0) { |
38 | return TRUE; |
39 | } |
40 | |
41 | } |
42 | return FALSE; |
43 | } |
44 | |
45 | /** |
46 | * {@inheritdoc} |
47 | */ |
48 | public function determineActiveTheme(RouteMatchInterface $route_match) { |
49 | // Get the visitors config. |
50 | $config = $this->configFactory->get('crm.settings'); |
51 | $theme = $config->get('theme') ?: 'admin'; |
52 | |
53 | return $this->configFactory->get('system.theme')->get($theme) ?: $theme; |
54 | } |
55 | |
56 | } |