Projet

Général

Profil

Paste
Télécharger (4,3 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / themes / adminimal_theme / theme-settings.php @ e4c061ad

1
<?php
2

    
3

    
4
/**
5
 * @file
6
 * Theme setting callbacks for the Adminimal theme.
7
 */
8

    
9
/**
10
 * Implements hook_form_FORM_ID_alter().
11
 *
12
 * @param $form
13
 *   The form.
14
 * @param $form_state
15
 *   The form state.
16
 */
17
function adminimal_form_system_theme_settings_alter(&$form, &$form_state) {
18

    
19
  // Get adminimal theme path.
20
  global $base_url;
21
  $adminimal_path = drupal_get_path('theme', 'adminimal');
22
  $old_css_path = $adminimal_path . '/css/custom.css';
23
  $custom_css_path = 'public://adminimal-custom.css';
24
  $custom_css_dir = str_replace($base_url . '/', "", file_create_url($custom_css_path));
25
  $custom_css_url = file_create_url($custom_css_path);
26

    
27
  // Try to create the adminimal-custom.css file automatically.
28
  if (!file_exists($custom_css_path)) {
29

    
30
    // Try to migrate from the old css.
31
    if (file_exists($old_css_path)) {
32
      file_unmanaged_copy($old_css_path, $custom_css_path, FILE_EXISTS_ERROR);
33
    }
34
    // Else create e new blank css file.
35
    else {
36
      file_unmanaged_save_data("", $custom_css_path, FILE_EXISTS_ERROR);
37
    }
38

    
39
  }
40

    
41
  // Notify user to remove his old css file.
42
  if (file_exists($old_css_path)) {
43
    drupal_set_message(t('Please delete the old @css_location file, as its no longer used.', array('@css_location file' => $old_css_path)), 'warning');
44
  }
45

    
46
  $form['adminimal_custom'] = array(
47
    '#type' => 'fieldset',
48
    '#title' => t('Adminimal Customization'),
49
    '#weight' => -10,
50
  );
51

    
52
  $form['adminimal_custom']['display_icons_config'] = array(
53
    '#type' => 'checkbox',
54
    '#title' => t('Display icons in Configuration page'),
55
    '#default_value' => theme_get_setting('display_icons_config'),
56
  );
57

    
58
  $form['adminimal_custom']['use_custom_media_queries'] = array(
59
    '#type' => 'checkbox',
60
    '#title' => t('Use Custom Media Queries'),
61
    '#description' => t('You can override the mobile and tablet media queries from this option. Use it only if you know what media queries are and how to use them.'),
62
    '#default_value' => theme_get_setting('use_custom_media_queries'),
63
  );
64

    
65
  $form['adminimal_custom']['media_queries'] = array(
66
    '#type' => 'fieldset',
67
    '#title' => t('Custom Media Queries'),
68
    '#states' => array(
69
      // Hide the settings when the cancel notify checkbox is disabled.
70
      'visible' => array(
71
       ':input[name="use_custom_media_queries"]' => array('checked' => TRUE),
72
      ),
73
     ),
74
  );
75

    
76
  $form['adminimal_custom']['media_queries']['media_query_mobile'] = array(
77
    '#type' => 'textfield',
78
    '#title' => t('Mobile media query'),
79
    '#description' => t('The media query to load the mobile.css styles.'),
80
    '#default_value' => theme_get_setting('media_query_mobile'),
81
  );
82

    
83
  $form['adminimal_custom']['media_queries']['media_query_tablet'] = array(
84
    '#type' => 'textfield',
85
    '#title' => t('Tablet media query'),
86
    '#description' => t('The media query to load the tablet.css styles.'),
87
    '#default_value' => theme_get_setting('media_query_tablet'),
88
  );
89

    
90
  $form['adminimal_custom']['custom_css'] = array(
91
    '#type' => 'checkbox',
92
    '#title' => t('Use "adminimal-custom.css"'),
93
    '#description' => t('Include adminimal-custom.css file to override or add custom css code without subthememing/hacking Adminimal Theme.'),
94
    '#default_value' => theme_get_setting('custom_css'),
95
  );
96

    
97
  $form['adminimal_custom']['adminimal_custom_check'] = array(
98
    '#type' => 'fieldset',
99
    '#title' => t('Custom CSS file check'),
100
    '#weight' => 50,
101
    '#states' => array(
102
      // Hide the settings when the cancel notify checkbox is disabled.
103
      'visible' => array(
104
       ':input[name="custom_css"]' => array('checked' => TRUE),
105
      ),
106
     ),
107
  );
108

    
109
  if (file_exists($custom_css_path)) {
110
    $form['adminimal_custom']['adminimal_custom_check']['custom_css_description'] = array(
111
      '#markup' => t('Custom CSS file Found in: !css', array('!css' => "<span class='css_path'>" . $custom_css_dir . "</span>")),
112
      '#prefix' => '<div class="messages status custom_css_found">',
113
      '#suffix' => '</div>',
114
    );
115
  }
116
  else {
117
    $form['adminimal_custom']['adminimal_custom_check']['custom_css_not_found'] = array(
118
      '#markup' => t('Custom CSS file not found. You must create the !css file manually.', array('!css' => "<span class='css_path'>" . $custom_css_dir . "</span>")),
119
      '#prefix' => '<div class="messages error custom_css_not_found">',
120
      '#suffix' => '</div>',
121
    );
122
  }
123
}