public function AssetInjectorBase::isActive in Asset Injector 8
Checks if the theme & page settings are appropriate for the given page.
Return value
bool If the asset is enabled & applicable to current page.
Overrides AssetInjectorInterface::isActive
File
- src/
Entity/ AssetInjectorBase.php, line 71
Class
- AssetInjectorBase
- Class AssetInjectorBase: Base asset injector class.
Namespace
Drupal\asset_injector\EntityCode
public function isActive() {
if (!$this
->status()) {
return FALSE;
}
$theme = Drupal::theme()
->getActiveTheme()
->getName();
if (empty($this->themes) || in_array($theme, $this->themes)) {
if (!empty($this->nodeType)) {
$node = Drupal::routeMatch()
->getParameter('node');
if (is_object($node) && $node
->getType() == $this->nodeType) {
return TRUE;
}
else {
return FALSE;
}
}
$pages = rtrim($this->pages);
if (empty($pages)) {
return TRUE;
}
$path = Drupal::service('path.current')
->getPath();
$path_alias = Unicode::strtolower(Drupal::service('path.alias_manager')
->getAliasByPath($path));
$page_match = Drupal::service('path.matcher')
->matchPath($path_alias, $pages) || $path != $path_alias && Drupal::service('path.matcher')
->matchPath($path, $pages);
// When $rule->visibility has a value of 0, the asset is
// added on all pages except those listed in $rule->pages.
// When set to 1, it is added only on those pages listed in $rule->pages.
if (!($this->visibility xor $page_match)) {
return TRUE;
}
}
return FALSE;
}