function _gin_toolbar_gin_is_active in Gin Toolbar 8
Helper function for check if Gin is active.
2 calls to _gin_toolbar_gin_is_active()
- gin_toolbar_page_attachments_alter in ./
gin_toolbar.module - Implements hook_preprocess_HOOK() for page_attachments.
- gin_toolbar_preprocess_html in ./
gin_toolbar.module - Implements hook_preprocess_HOOK() for html.
File
- ./
gin_toolbar.module, line 221 - gin_toolbar.module
Code
function _gin_toolbar_gin_is_active() {
// Check if permissions are given.
if (!\Drupal::currentUser()
->hasPermission('access toolbar')) {
return FALSE;
}
$logged_in = \Drupal::currentUser()
->isAuthenticated();
$theme_handler = \Drupal::service('theme_handler')
->listInfo();
// Check if set as frontend theme.
$frontend_theme_name = \Drupal::config('system.theme')
->get('default');
// Check if base themes are set.
if (isset($theme_handler[$frontend_theme_name]->base_themes)) {
$frontend_base_themes = $theme_handler[$frontend_theme_name]->base_themes;
}
// Add theme name to base theme array.
$frontend_base_themes[$frontend_theme_name] = $frontend_theme_name;
// Check if set as admin theme.
$admin_theme_name = \Drupal::config('system.theme')
->get('admin');
// Admin theme will have no value if is set to use the default theme.
if ($admin_theme_name && isset($theme_handler[$admin_theme_name]->base_themes)) {
$admin_base_themes = $theme_handler[$admin_theme_name]->base_themes;
$admin_base_themes[$admin_theme_name] = $admin_theme_name;
}
else {
$admin_base_themes = $frontend_base_themes;
}
// Check if Gin is activated in the frontend.
if ($logged_in) {
$gin_activated = array_key_exists('gin', $admin_base_themes);
}
else {
$gin_activated = array_key_exists('gin', $frontend_base_themes);
}
// Is Gin in the active chain?
$theme_activated = $gin_activated;
return $theme_activated;
}