class Engine in ThemeKey 8
Hierarchy
- class \Drupal\themekey\Engine\Engine implements EngineInterface uses OperatorManagerTrait, PropertyManagerTrait, RuleChainManagerTrait
Expanded class hierarchy of Engine
1 string reference to 'Engine'
1 service uses Engine
File
- src/
Engine/ Engine.php, line 20
Namespace
Drupal\themekey\EngineView source
class Engine implements EngineInterface {
use PropertyManagerTrait;
use OperatorManagerTrait;
use RuleChainManagerTrait;
/**
* The system theme config object.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
protected $routeMatch;
/**
* Constructs a DefaultNegotiator object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
*/
public function __construct(ConfigFactoryInterface $config_factory) {
$this->configFactory = $config_factory;
}
/**
* @return \Drupal\Core\Routing\RouteMatchInterface
*/
public function getRouteMatch() {
return $this->routeMatch;
}
/**
* @return \Drupal\Core\Config\ConfigFactoryInterface
*/
public function getConfigFactory() {
return $this->configFactory;
}
/**
* {@inheritdoc}
*/
public function determineTheme(RouteMatchInterface $route_match) {
$this->routeMatch = $route_match;
#var_dump($route_match);
$ruleChainManager = $this
->getRuleChainManager();
$chain = $ruleChainManager
->getOptimizedChain();
return $chain ? $this
->walkRuleChildren($chain) : NULL;
}
protected function walkRuleChildren($chain, $theme = NULL, $parent = 0) {
$has_children = FALSE;
foreach ($chain as $ruleId => $ruleMetaData) {
if ($ruleMetaData['parent'] == $parent) {
$has_children = TRUE;
$rule = ThemeKeyRule::load($ruleId);
if ($this
->matchCondition($rule)) {
$theme = $this
->walkRuleChildren($chain, $rule
->theme(), $ruleId);
if ($theme) {
return $theme;
}
}
}
}
// No children: return theme of parent.
// Has children: all children did not match => return no theme.
return $has_children ? NULL : $theme;
}
/**
* Detects if a ThemeKey rule matches to the current
* page request.
*
* @param object $rule
* ThemeKey rule as object:
* - property
* - operator
* - value
*
* @return bool
*/
protected function matchCondition(ThemeKeyRuleInterface $rule) {
$operator = $this
->getOperatorManager()
->createInstance($rule
->operator());
$property = $this
->getPropertyManager()
->createInstance($rule
->property());
$property
->setEngine($this);
#drupal_set_message(print_r($property->getValues(), TRUE));
$values = $property
->getValues();
$key = $rule
->key();
if (!is_null($key)) {
if (isset($values[$key])) {
return $operator
->evaluate($values[$key], $rule
->value());
}
}
else {
foreach ($values as $value) {
if ($operator
->evaluate($value, $rule
->value())) {
return TRUE;
}
}
}
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Engine:: |
protected | property | The system theme config object. | |
Engine:: |
protected | property | ||
Engine:: |
public | function |
Determine the active theme for the request. Overrides EngineInterface:: |
|
Engine:: |
public | function |
Overrides EngineInterface:: |
|
Engine:: |
public | function |
Overrides EngineInterface:: |
|
Engine:: |
protected | function | Detects if a ThemeKey rule matches to the current page request. | |
Engine:: |
protected | function | ||
Engine:: |
public | function | Constructs a DefaultNegotiator object. | |
OperatorManagerTrait:: |
private | property | @var | |
OperatorManagerTrait:: |
protected | function | Gets the ThemeKey Operator manager. | |
OperatorManagerTrait:: |
public | function | Sets the ThemeKey Property manager to use. | |
PropertyManagerTrait:: |
private | property | @var | |
PropertyManagerTrait:: |
protected | function | Gets the ThemeKey Property manager. | |
PropertyManagerTrait:: |
public | function | Sets the ThemeKey Property manager to use. | |
RuleChainManagerTrait:: |
private | property | @var | |
RuleChainManagerTrait:: |
protected | function | Gets the ThemeKey Rule Chain manager. | 1 |
RuleChainManagerTrait:: |
public | function | Sets the ThemeKey Rule Chain manager to use. |