less.admin.inc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /**
  3. * @file
  4. * Contains the administration pages for LESS.
  5. */
  6. /**
  7. * Form for LESS module settings.
  8. */
  9. function less_settings_form($form, &$form_state) {
  10. $form['less_flush'] = array(
  11. '#type' => 'fieldset',
  12. '#collapsible' => FALSE,
  13. '#value' => t('Click this button to flag all LESS files for regeneration.'),
  14. );
  15. $form['less_flush']['flush'] = array(
  16. '#type' => 'submit',
  17. '#submit' => array('_flush_less'),
  18. '#value' => t('Flush LESS files'),
  19. );
  20. $registered_engines = _less_get_engines();
  21. $less_engines = array();
  22. foreach ($registered_engines as $library => $engine) {
  23. $less_engines[] = libraries_detect($library);
  24. }
  25. $less_engine_element = array(
  26. '#type' => 'radios',
  27. '#title' => t('LESS engine'),
  28. '#options' => array(),
  29. '#required' => TRUE,
  30. '#default_value' => variable_get('less_engine', 'lessphp'),
  31. );
  32. foreach ($less_engines as $less_engine) {
  33. $less_engine_element['#options'][$less_engine['machine name']] = $less_engine['name'];
  34. $less_engine_element[$less_engine['machine name']] = array(
  35. '#type' => 'radio',
  36. '#title' => t('@engine_name - <a href="@vendor_url">@vendor_url</a>', array('@engine_name' => $less_engine['name'], '@vendor_url' => $less_engine['vendor url'])),
  37. '#return_value' => $less_engine['machine name'],
  38. '#description' => t('Missing - Click vendor link above to read installation instructions.'),
  39. '#disabled' => empty($less_engine['installed']),
  40. );
  41. if ($less_engine['installed']) {
  42. $less_engine_element[$less_engine['machine name']]['#description'] = t('v%version Installed', array('%version' => $less_engine['version']));
  43. }
  44. }
  45. $form['less_engine'] = $less_engine_element;
  46. $lessautoprefixer_library = libraries_detect('lessautoprefixer');
  47. $form[LESS_AUTOPREFIXER] = array(
  48. '#type' => 'checkbox',
  49. '#title' => t('Use @name - <a href="@vendor_url">@vendor_url</a>', array('@name' => $lessautoprefixer_library['name'], '@vendor_url' => $lessautoprefixer_library['vendor url'])),
  50. '#description' => t('Enable automatic prefixing of vendor CSS extensions.'),
  51. '#default_value' => variable_get(LESS_AUTOPREFIXER, FALSE),
  52. '#disabled' => empty($lessautoprefixer_library['installed']),
  53. );
  54. if ($lessautoprefixer_library['installed']) {
  55. $form[LESS_AUTOPREFIXER]['#description'] .= '<br />'. t('v%version Installed', array('%version' => $lessautoprefixer_library['version']));
  56. }
  57. $form['developer_options'] = array(
  58. '#type' => 'fieldset',
  59. '#title' => t('Developer Options'),
  60. '#collapsible' => TRUE,
  61. '#collapsed' => !(variable_get(LESS_DEVEL, FALSE)),
  62. );
  63. $form['developer_options'][LESS_DEVEL] = array(
  64. '#type' => 'checkbox',
  65. '#title' => t('Developer Mode'),
  66. '#description' => t('Enable developer mode to ensure LESS files are regenerated every page load.'),
  67. '#default_value' => variable_get(LESS_DEVEL, FALSE),
  68. );
  69. $form['developer_options'][LESS_SOURCE_MAPS] = array(
  70. '#type' => 'checkbox',
  71. '#title' => t('Source Maps'),
  72. '#description' => t('Enable source maps output while "Developer Mode" is enabled.'),
  73. '#default_value' => variable_get(LESS_SOURCE_MAPS, FALSE),
  74. '#states' => array(
  75. 'enabled' => array(
  76. ':input[name="' . LESS_DEVEL . '"]' => array('checked' => TRUE),
  77. ),
  78. ),
  79. );
  80. $form['developer_options'][LESS_WATCH] = array(
  81. '#type' => 'checkbox',
  82. '#title' => t('Watch Mode'),
  83. '#description' => t('Enable watch mode while developer mode is active to automatically reload styles when changes are detected, including changes to @import-ed files. Does not cause a page reload.'),
  84. '#default_value' => variable_get(LESS_WATCH, FALSE),
  85. '#states' => array(
  86. 'enabled' => array(
  87. ':input[name="' . LESS_DEVEL . '"]' => array('checked' => TRUE),
  88. ),
  89. ),
  90. );
  91. $form['#submit'] = array('less_settings_form_submit');
  92. return system_settings_form($form);
  93. }
  94. /**
  95. * Form submission function.
  96. *
  97. * Trigger clear of LESS module cache data.
  98. */
  99. function less_settings_form_submit($form, &$form_state) {
  100. cache_clear_all('less:', 'cache', TRUE);
  101. }
  102. /**
  103. * Submit handler for cache clear button.
  104. */
  105. function _flush_less($form, &$form_state) {
  106. less_flush_caches();
  107. drupal_set_message(t('LESS files cache cleared.'), 'status');
  108. }