You are here

admin_css.module in Admin CSS 8

Hook implementations for the Admin CSS module.

File

admin_css.module
View source
<?php

/**
 * @file
 * Hook implementations for the Admin CSS module.
 */

/**
 * Implements hook_page_attachments().
 */
function admin_css_page_attachments(array &$page) {
  $theme = \Drupal::theme()
    ->getActiveTheme()
    ->getName();
  $def_theme = Drupal::config('system.theme')
    ->get('default');
  if ($def_theme === $theme) {
    if (file_exists('public://admin-style.css')) {
      $page['#attached']['library'][] = $theme . '/admin_css.admin_css';
    }
  }
}

/**
 * Implements hook_library_info_alter().
 */
function admin_css_library_info_alter(&$libraries, $extension) {
  $theme = \Drupal::theme()
    ->getActiveTheme()
    ->getName();
  if ($theme === $extension) {
    if (!isset($libraries['admin_css.admin_css']['css'])) {

      // Add the library to the active theme with a relatively high weight.
      $libraries['admin_css.admin_css']['css']['theme']['public://admin-style.css']['weight'] = 9999;
    }
  }
}