123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- /**
- * @file
- * Functions to support theming in the Adminimal theme.
- */
- use Drupal\Core\Form\FormStateInterface;
- /**
- * Implements hook_preprocess_HOOK() for HTML document templates.
- */
- function adminimal_theme_preprocess_html(&$variables) {
- // Add adminimal class to the body.
- $variables['attributes']['class'][] = 'adminimal';
- // Add library with custom CSS.
- if (theme_get_setting('custom_css')) {
- $variables['#attached']['library'][] = 'adminimal_theme/custom-styling';
- }
- }
- /**
- * Implements hook_form_system_theme_settings_alter().
- */
- function adminimal_theme_form_system_theme_settings_alter(&$form, \Drupal\Core\Form\FormStateInterface &$form_state, $form_id = NULL) {
- // Work-around for a core bug affecting admin themes. See issue #943212.
- if (isset($form_id)) {
- return;
- }
- // Get adminimal theme path.
- global $base_url;
- $adminimal_path = drupal_get_path('theme', 'adminimal_theme');
- $old_css_path = $adminimal_path . '/css/custom.css';
- $custom_css_path = 'public://adminimal-custom.css';
- $custom_css_dir = str_replace($base_url . '/', "", file_create_url($custom_css_path));
- $custom_css_url = file_create_url($custom_css_path);
- // Try to create the adminimal-custom.css file automatically.
- if (!file_exists($custom_css_path)) {
- // Try to migrate from the old css.
- if (file_exists($old_css_path)) {
- file_unmanaged_copy($old_css_path, $custom_css_path, FILE_EXISTS_ERROR);
- }
- // Else create a new blank css file.
- else {
- file_unmanaged_save_data("", $custom_css_path, FILE_EXISTS_ERROR);
- }
- }
- // Notify user to remove his old css file.
- if (file_exists($old_css_path)) {
- drupal_set_message(t('Please delete the old @css_location file, as its no longer used.', ['@css_location file' => $old_css_path]), 'warning');
- }
- $form['adminimal_custom'] = [
- '#type' => 'fieldset',
- '#title' => t('Adminimal Customization'),
- '#weight' => -10,
- ];
- $form['adminimal_custom']['custom_css'] = [
- '#type' => 'checkbox',
- '#title' => t('Use "adminimal-custom.css"'),
- '#description' => t('Include adminimal-custom.css file to override or add custom css code without subthememing/hacking Adminimal Theme.'),
- '#default_value' => theme_get_setting('custom_css'),
- ];
- $form['adminimal_custom']['adminimal_custom_check'] = [
- '#type' => 'fieldset',
- '#title' => t('Custom CSS file check'),
- '#weight' => 50,
- '#states' => [
- // Hide the settings when the cancel notify checkbox is disabled.
- 'visible' => [
- ':input[name="custom_css"]' => ['checked' => TRUE],
- ],
- ],
- ];
- if (file_exists($custom_css_path)) {
- $form['adminimal_custom']['adminimal_custom_check']['custom_css_description'] = [
- '#type' => 'container',
- '#attributes' => [
- 'class' => ['messages', 'messages--status'],
- ],
- 'message' => [
- '#markup' => t('Custom CSS file Found in: @css', ['@css' => $custom_css_dir]),
- ],
- ];
- }
- else {
- $form['adminimal_custom']['adminimal_custom_check']['custom_css_not_found'] = [
- '#type' => 'container',
- '#attributes' => [
- 'class' => ['messages', 'messages--error'],
- ],
- 'message' => [
- '#markup' => t('Custom CSS file not found. You must create the @css file manually.', ['@css' => $custom_css_dir]),
- ],
- ];
- }
- }
|