respondjs.install 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Implements hook_requirements().
  4. */
  5. function respondjs_requirements($phase) {
  6. $requirements = array();
  7. if ($phase == "runtime") {
  8. $library_path = respondjs_get_library_file();
  9. $requirements['respondjs'] = array(
  10. 'title' => t('Respond.js script'),
  11. 'value' => t('Enabled'),
  12. );
  13. // If CSS aggregated is not enabled, inform users it will not work.
  14. if (variable_get('preprocess_css') != 1) {
  15. $requirements['respondjs']['value'] = t('Respond.js will not work with CSS aggregation disabled.');
  16. if (variable_get('respondjs_quiet', RESPONDJS_QUIET_DEFAULT) == 1) {
  17. // If user disabled the warning, reduce severity of this requirement.
  18. $requirements['respondjs']['severity'] = REQUIREMENT_WARNING;
  19. $requirements['respondjs']['description'] = t('The Respond.js module is enabled, but CSS aggregation is disabled. The script cannot function until <a href="@url">CSS agregation is enabled</a>.', array('@url' => url('admin/config/development/performance', array('query' => array('destination' => request_path())))));
  20. }
  21. else {
  22. // By default, failure to enable aggregation results in admin warning.
  23. $requirements['respondjs']['severity'] = REQUIREMENT_ERROR;
  24. $requirements['respondjs']['description'] = t('The Respond.js module is enabled, but CSS aggregation is disabled. The script cannot function until <a href="@url1">CSS agregation is enabled</a>. You can <a href="@url2">disable this warning</a>.', array('@url1' => url('admin/config/development/performance', array('query' => array('destination' => request_path()))), '@url2' => url('admin/config/media/respondjs', array('query' => array('destination' => request_path())))));
  25. }
  26. }
  27. // If any of the next requirements are unsuccessful, they negate the need to
  28. // inform the user about CSS aggregation. So we're intentionally overwriting
  29. // the $requirements values we just set above.
  30. // If Libraries API is enabled but respond.js is not found within the
  31. // sites/all/libraries folder, then report a warning. The module will fall
  32. // back to its included copy so this isn't a showstopper.
  33. if (function_exists('libraries_get_path') && strpos($library_path,'libraries/respondjs') === FALSE) {
  34. $requirements['respondjs']['value'] = t('Respond.js is not correctly using Libraries API');
  35. $requirements['respondjs']['severity'] = REQUIREMENT_WARNING;
  36. $requirements['respondjs']['description'] = t('Please install !respondjs in <b>@libraries</b>. The module is using its included copy at <b>@default</b>.', array(
  37. '!respondjs' => l('respond.min.js', RESPONDJS_DOWNLOAD_URI),
  38. '@libraries' => RESPONDJS_DOWNLOAD_LOCATION,
  39. '@default' => drupal_get_path('module','respondjs') . '/lib')
  40. );
  41. }
  42. // If the included copy of respond.js has been removed or renamed report an error.
  43. // At this point the module cannot function properly.
  44. if (!file_exists($library_path)) {
  45. $requirements['respondjs']['value'] = t('Respond.js is not correctly installed');
  46. $requirements['respondjs']['severity'] = REQUIREMENT_ERROR;
  47. $requirements['respondjs']['description'] = t('Please install !respondjs in <strong>@libraries</strong>', array(
  48. '!respondjs' => l('Respond.js', RESPONDJS_DOWNLOAD_URI),
  49. '@libraries' => RESPONDJS_DOWNLOAD_LOCATION,
  50. ));
  51. }
  52. }
  53. return $requirements;
  54. }
  55. /**
  56. * Implements hook_uninstall().
  57. */
  58. function respondjs_uninstall() {
  59. variable_del('respondjs_scope');
  60. variable_del('respondjs_quiet');
  61. }