theme-settings.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * @file
  4. * Theme setting callbacks for the Adminimal theme.
  5. */
  6. /**
  7. * Implements hook_form_FORM_ID_alter().
  8. *
  9. * @param $form
  10. * The form.
  11. * @param $form_state
  12. * The form state.
  13. */
  14. function adminimal_form_system_theme_settings_alter(&$form, &$form_state) {
  15. // Get adminimal theme path.
  16. global $base_url;
  17. $adminimal_path = drupal_get_path('theme', 'adminimal');
  18. $old_css_path = $adminimal_path . '/css/custom.css';
  19. $custom_css_path = 'public://adminimal-custom.css';
  20. $custom_css_dir = str_replace($base_url . '/', "", file_create_url($custom_css_path));
  21. $custom_css_url = file_create_url($custom_css_path);
  22. // Try to create the adminimal-custom.css file automatically.
  23. if (!file_exists($custom_css_path)) {
  24. // Try to migrate from the old css.
  25. if (file_exists($old_css_path)) {
  26. file_unmanaged_copy($old_css_path, $custom_css_path, FILE_EXISTS_ERROR);
  27. }
  28. // Else create e new blank css file.
  29. else {
  30. file_unmanaged_save_data("", $custom_css_path, FILE_EXISTS_ERROR);
  31. }
  32. }
  33. // Notify user to remove his old css file.
  34. if (file_exists($old_css_path)) {
  35. drupal_set_message(t('Please delete the old @css_location file, as its no longer used.', array('@css_location file' => $old_css_path)), 'warning');
  36. }
  37. $form['adminimal_custom'] = array(
  38. '#type' => 'fieldset',
  39. '#title' => t('Adminimal Customization'),
  40. '#weight' => -10,
  41. );
  42. $form['adminimal_custom']['display_icons_config'] = array(
  43. '#type' => 'checkbox',
  44. '#title' => t('Display icons in Configuration page'),
  45. '#default_value' => theme_get_setting('display_icons_config'),
  46. );
  47. $form['adminimal_custom']['use_custom_media_queries'] = array(
  48. '#type' => 'checkbox',
  49. '#title' => t('Use Custom Media Queries'),
  50. '#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.'),
  51. '#default_value' => theme_get_setting('use_custom_media_queries'),
  52. );
  53. $form['adminimal_custom']['media_queries'] = array(
  54. '#type' => 'fieldset',
  55. '#title' => t('Custom Media Queries'),
  56. '#states' => array(
  57. // Hide the settings when the cancel notify checkbox is disabled.
  58. 'visible' => array(
  59. ':input[name="use_custom_media_queries"]' => array('checked' => TRUE),
  60. ),
  61. ),
  62. );
  63. $form['adminimal_custom']['media_queries']['media_query_mobile'] = array(
  64. '#type' => 'textfield',
  65. '#title' => t('Mobile media query'),
  66. '#description' => t('The media query to load the mobile.css styles.'),
  67. '#default_value' => theme_get_setting('media_query_mobile'),
  68. );
  69. $form['adminimal_custom']['media_queries']['media_query_tablet'] = array(
  70. '#type' => 'textfield',
  71. '#title' => t('Tablet media query'),
  72. '#description' => t('The media query to load the tablet.css styles.'),
  73. '#default_value' => theme_get_setting('media_query_tablet'),
  74. );
  75. $form['adminimal_custom']['custom_css'] = array(
  76. '#type' => 'checkbox',
  77. '#title' => t('Use "adminimal-custom.css"'),
  78. '#description' => t('Include adminimal-custom.css file to override or add custom css code without subthememing/hacking Adminimal Theme.'),
  79. '#default_value' => theme_get_setting('custom_css'),
  80. );
  81. $form['adminimal_custom']['adminimal_custom_check'] = array(
  82. '#type' => 'fieldset',
  83. '#title' => t('Custom CSS file check'),
  84. '#weight' => 50,
  85. '#states' => array(
  86. // Hide the settings when the cancel notify checkbox is disabled.
  87. 'visible' => array(
  88. ':input[name="custom_css"]' => array('checked' => TRUE),
  89. ),
  90. ),
  91. );
  92. if (file_exists($custom_css_path)) {
  93. $form['adminimal_custom']['adminimal_custom_check']['custom_css_description'] = array(
  94. '#markup' => t('Custom CSS file Found in: !css', array('!css' => "<span class='css_path'>" . $custom_css_dir . "</span>")),
  95. '#prefix' => '<div class="messages status custom_css_found">',
  96. '#suffix' => '</div>',
  97. );
  98. }
  99. else {
  100. $form['adminimal_custom']['adminimal_custom_check']['custom_css_not_found'] = array(
  101. '#markup' => t('Custom CSS file not found. You must create the !css file manually.', array('!css' => "<span class='css_path'>" . $custom_css_dir . "</span>")),
  102. '#prefix' => '<div class="messages error custom_css_not_found">',
  103. '#suffix' => '</div>',
  104. );
  105. }
  106. }