admincss-8.x-2.2/admincss.module
admincss.module
<?php /** * @file * Hook implementations for the Admin CSS module. */ use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Routing\RouteMatchInterface; /** * Implements hook_help(). */ function admincss_help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.admincss': $output = ''; $output .= '<h3>' . t('About') . '</h3>'; $output .= '<p>' . t('The Admin CSS module provides a way to add custom CSS to the site.') . '</p>'; return $output; } } /** * Implements hook_page_attachments(). */ function admincss_page_attachments(array &$attachments) { $theme = \Drupal::theme()->getActiveTheme()->getName(); $default_theme = \Drupal::config('system.theme')->get('default'); if ($default_theme === $theme) { if (file_exists('public://admin-style.css')) { $attachments['#attached']['library'][] = $theme . '/admincss.admincss'; } // Add the admin css cache tags. $admincss_config = \Drupal::config('admincss.settings'); $cacheable_metadata = CacheableMetadata::createFromObject($admincss_config); $cacheable_metadata->applyTo($attachments); } } /** * Implements hook_library_info_alter(). */ function admincss_library_info_alter(&$libraries, $extension) { $theme = \Drupal::theme()->getActiveTheme()->getName(); if ($theme === $extension) { if (!isset($libraries['admincss.admincss']['css'])) { // Add the library to the active theme with a relatively high weight. $libraries['admincss.admincss']['css']['theme']['public://admin-style.css']['weight'] = 9999; } } }