VisualDiffThemeNegotiator.php in Diff 8
File
src/VisualDiffThemeNegotiator.php
View source
<?php
namespace Drupal\diff;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Theme\ThemeNegotiatorInterface;
class VisualDiffThemeNegotiator implements ThemeNegotiatorInterface {
protected $configFactory;
public function __construct(ConfigFactoryInterface $config_factory) {
$this->configFactory = $config_factory;
}
public function applies(RouteMatchInterface $routeMatch) {
if ($routeMatch
->getParameter('filter') !== 'visual_inline') {
return FALSE;
}
if (!$this
->isDiffRoute($routeMatch)) {
return FALSE;
}
if ($this->configFactory
->get('diff.settings')
->get('general_settings.visual_inline_theme') !== 'default') {
return FALSE;
}
return TRUE;
}
public function determineActiveTheme(RouteMatchInterface $route_match) {
return $this->configFactory
->get('system.theme')
->get('default');
}
protected function isDiffRoute(RouteMatchInterface $route_match) {
$regex_pattern = '/^entity\\..*\\.revisions_diff$/';
return $route_match
->getRouteName() === 'diff.revisions_diff' || preg_match($regex_pattern, $route_match
->getRouteName());
}
}