function ThemeHooks::pageAttachmentsAlter
Same name in this branch
- main core/themes/admin/src/Hook/ThemeHooks.php \Drupal\admin\Hook\ThemeHooks::pageAttachmentsAlter()
Same name and namespace in other branches
- 11.x core/themes/admin/src/Hook/ThemeHooks.php \Drupal\admin\Hook\ThemeHooks::pageAttachmentsAlter()
- 11.x core/themes/default_admin/src/Hook/ThemeHooks.php \Drupal\default_admin\Hook\ThemeHooks::pageAttachmentsAlter()
Implements hook_page_attachments_alter().
Attributes
#[Hook('page_attachments_alter')]
File
-
core/
themes/ default_admin/ src/ Hook/ ThemeHooks.php, line 106
Class
- ThemeHooks
- Provides theme related hook implementations.
Namespace
Drupal\default_admin\HookCode
public function pageAttachmentsAlter(array &$page) : void {
$theme_path = $this->requestStack
->getCurrentRequest()?->getBasePath() . '/' . $this->themeExtensionList
->getPath('default_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'][] = 'default_admin/init';
// Attach breadcrumb styles.
$page['#attached']['library'][] = 'default_admin/breadcrumb';
// Attach accent library.
$page['#attached']['library'][] = 'default_admin/accent';
// Attach sticky library.
$page['#attached']['library'][] = 'default_admin/sticky';
$settings = Settings::getInstance();
// Expose theme settings to JS.
$default_admin_settings = [
'dark_mode' => $settings->get('enable_dark_mode'),
'dark_mode_class' => 'dark-mode',
'accent_colors' => Helper::accentColors(),
'preset_accent_color' => $settings->get('preset_accent_color'),
'accent_color' => $settings->get('accent_color'),
'preset_focus_color' => $settings->get('preset_focus_color'),
'focus_color' => $settings->get('focus_color'),
'high_contrast_mode' => $settings->get('high_contrast_mode'),
'high_contrast_mode_class' => 'high-contrast-mode',
'show_user_theme_settings' => $settings->get('show_user_theme_settings'),
];
$page['#attached']['drupalSettings']['defaultAdmin'] = $default_admin_settings;
// Retain the previous key for integrations while the theme is experimental.
$page['#attached']['drupalSettings']['gin'] = $default_admin_settings;
$page['#attached']['html_head'][] = [
[
'#tag' => 'script',
'#attributes' => [
'type' => 'application/json',
'id' => 'default-admin-setting-dark_mode',
],
'#value' => new FormattableMarkup('{ "defaultAdminDarkMode": "@value" }', [
'@value' => $settings->get('enable_dark_mode') ?? 'unknown',
]),
],
'default_admin_dark_mode',
];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.