You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
39 lines
1.1 KiB
<?php |
|
|
|
use Drupal\Core\Render\AttachmentsTrait; |
|
|
|
/** |
|
* Implements hook_page_attachments(). |
|
*/ |
|
function mobile_facets_page_attachments(array &$attachments) { |
|
$attachments['#attached']['library'][] = 'mobile_facets/mobile_facets'; |
|
} |
|
|
|
/** |
|
* @file |
|
* Contains mobile_facets.module. |
|
*/ |
|
|
|
/** |
|
* Implements hook_preprocess_html(). |
|
*/ |
|
function mobile_facets_preprocess_html(&$variables) { |
|
$config = \Drupal::config('mobile_facets.settings'); |
|
$color = $config->get('color') ?? '#000000'; |
|
|
|
// Preload the CSS from the module path (theme-agnostic). |
|
$css_path = \Drupal::service('extension.list.module')->getPath('mobile_facets') . '/css/mobile_facets.css'; |
|
$variables['#attached']['html_head_link'][] = [ |
|
[ |
|
'rel' => 'preload', |
|
'as' => 'style', |
|
'href' => $css_path, |
|
], |
|
]; |
|
|
|
// Add the CSS variable to <html> attributes (global across all themes). |
|
$variables['html_attributes']['style'] = '--mobile_facets-color: ' . $color . ';'; |
|
|
|
// Optionally attach the library if not already (loads CSS from module). |
|
//$variables['#attached']['library'][] = 'mobile_facets/mobile_facets'; |
|
}
|
|
|