function ThemeHooks::pageAttachmentsAlter
Same name and namespace in other branches
- 11.x core/themes/admin/src/Hook/ThemeHooks.php \Drupal\admin\Hook\ThemeHooks::pageAttachmentsAlter()
Implements hook_page_attachments_alter().
Attributes
#[Hook('page_attachments_alter')]
File
-
core/
themes/ admin/ src/ Hook/ ThemeHooks.php, line 160
Class
- ThemeHooks
- Provides theme related hook implementations.
Namespace
Drupal\admin\HookCode
public function pageAttachmentsAlter(array &$page) : void {
$theme_path = $this->requestStack
->getCurrentRequest()?->getBasePath() . '/' . $this->themeExtensionList
->getPath('admin');
$query_string = $this->assetQueryString
->get();
// Attach non-JavaScript specific CSS via a noscript tag to prevent unwanted
// layout shifts.
$page['#attached']['html_head'][] = [
[
'#tag' => 'link',
'#noscript' => TRUE,
'#attributes' => [
'rel' => 'stylesheet',
'href' => $theme_path . '/css/components/dropbutton-noscript.css?' . $query_string,
],
],
'dropbutton_noscript',
];
$page['#attached']['html_head'][] = [
[
'#tag' => 'link',
'#noscript' => TRUE,
'#attributes' => [
'rel' => 'stylesheet',
'href' => $theme_path . '/css/components/views-ui-noscript.css?' . $query_string,
],
],
'views_ui_noscript',
];
// Attach the init script.
$page['#attached']['library'][] = 'admin/init';
// Attach breadcrumb styles.
$page['#attached']['library'][] = 'admin/breadcrumb';
// Attach accent library.
$page['#attached']['library'][] = 'admin/accent';
// Attach sticky library.
$page['#attached']['library'][] = 'admin/sticky';
// Custom CSS file.
if (file_exists('public://admin-custom.css')) {
$page['#attached']['library'][] = 'admin/admin_custom_css';
}
$settings = Settings::getInstance();
// Expose theme settings to JS.
$page['#attached']['drupalSettings']['gin']['dark_mode'] = $settings->get('enable_dark_mode');
$page['#attached']['drupalSettings']['gin']['dark_mode_class'] = 'gin--dark-mode';
$page['#attached']['drupalSettings']['gin']['accent_colors'] = Helper::accentColors();
$page['#attached']['drupalSettings']['gin']['preset_accent_color'] = $settings->get('preset_accent_color');
$page['#attached']['drupalSettings']['gin']['accent_color'] = $settings->get('accent_color');
$page['#attached']['drupalSettings']['gin']['preset_focus_color'] = $settings->get('preset_focus_color');
$page['#attached']['drupalSettings']['gin']['focus_color'] = $settings->get('focus_color');
$page['#attached']['drupalSettings']['gin']['high_contrast_mode'] = $settings->get('high_contrast_mode');
$page['#attached']['drupalSettings']['gin']['high_contrast_mode_class'] = 'gin--high-contrast-mode';
$page['#attached']['drupalSettings']['gin']['show_user_theme_settings'] = $settings->get('show_user_theme_settings');
// Expose stylesheets to JS.
$base_theme_url = '/' . $this->themeExtensionList
->getPath('admin');
$page['#attached']['drupalSettings']['gin']['variables_css_path'] = $base_theme_url . '/migration/css/theme/variables.css';
$page['#attached']['drupalSettings']['gin']['accent_css_path'] = $base_theme_url . '/migration/css/theme/accent.css';
$page['#attached']['html_head'][] = [
[
'#tag' => 'script',
'#attributes' => [
'type' => 'application/json',
'id' => 'gin-setting-dark_mode',
],
'#value' => new FormattableMarkup('{ "ginDarkMode": "@value" }', [
'@value' => $settings->get('enable_dark_mode') ?? 'unknown',
]),
],
'gin_dark_mode',
];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.