log_filter.admin.inc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * @file
  4. * Drupal Log Filter module
  5. */
  6. /**
  7. * Defines configuration form fields.
  8. *
  9. * @param array $form
  10. * @param array &$form_state
  11. * @return array
  12. * - the return value of system_settings_form()
  13. */
  14. function _log_filter_admin_form($form, &$form_state) {
  15. module_load_include('inc', 'log_filter', 'LogFilter');
  16. if (variable_get('log_filter_css', TRUE)) {
  17. drupal_add_css(
  18. ($path = drupal_get_path('module', 'log_filter')) . '/admin/log_filter.admin.css',
  19. array('type' => 'file', 'group' => CSS_DEFAULT, 'preprocess' => FALSE, 'every_page' => FALSE)
  20. );
  21. }
  22. // Clear menu cache if just submitted.
  23. if (!empty($_SESSION) && !empty($_SESSION['module']) && !empty($_SESSION['module']['log_filter'])
  24. && array_key_exists('admin_form_submitted', $_SESSION['module']['log_filter'])) {
  25. menu_rebuild();
  26. unset($_SESSION['module']['log_filter']['admin_form_submitted']);
  27. if (empty($_SESSION['module']['log_filter'])) {
  28. unset($_SESSION['module']['log_filter']);
  29. if (empty($_SESSION['module'])) {
  30. unset($_SESSION['module']);
  31. }
  32. }
  33. }
  34. $form['general'] = array(
  35. '#type' => 'fieldset',
  36. '#title' => t('General settings'),
  37. '#collapsible' => FALSE,
  38. '#collapsed' => FALSE,
  39. 'log_filter_admintheme' => array(
  40. '#type' => 'checkbox',
  41. '#title' => t('Do always use the administrative theme on log view pages'),
  42. '#default_value' => variable_get('log_filter_admintheme', TRUE),
  43. '#attributes' => array('autocomplete' => 'off'),
  44. ),
  45. 'log_filter_cssdefault' => array(
  46. '#type' => 'checkbox',
  47. '#title' => t('Link this module\'s default stylesheet'),
  48. '#description' => t('Otherwise, implement styling in the site\'s theme layer.'),
  49. '#default_value' => variable_get('log_filter_cssdefault', TRUE),
  50. '#attributes' => array('autocomplete' => 'off'),
  51. ),
  52. );
  53. $form['log_list'] = array(
  54. '#type' => 'fieldset',
  55. '#title' => t('Log list settings'),
  56. '#collapsible' => FALSE,
  57. '#collapsed' => FALSE,
  58. 'log_filter_pgrng' => array(
  59. '#type' => 'textfield',
  60. '#title' => t('Default log list page range'),
  61. '#default_value' => variable_get('log_filter_pgrng', LogFilter::PAGE_RANGE_DEFAULT),
  62. '#attributes' => array('autocomplete' => 'off'),
  63. '#size' => 3,
  64. ),
  65. 'log_filter_trnslt' => array(
  66. '#type' => 'checkbox',
  67. '#title' => t('Default to translate log message'),
  68. '#description' => t('Translating log messages is heavy performance-wise'),
  69. '#default_value' => variable_get('log_filter_trnslt', FALSE),
  70. '#attributes' => array('autocomplete' => 'off'),
  71. ),
  72. 'log_filter_showdeletions' => array(
  73. '#type' => 'checkbox',
  74. '#title' => t('List log entries that record that logs have been deleted'),
  75. '#description' => t('Log entries of type \'log_filter delete logs\' defaults to be hidden, unless when that type is selected specifically.'),
  76. '#default_value' => variable_get('log_filter_showdeletions', FALSE),
  77. '#attributes' => array('autocomplete' => 'off'),
  78. ),
  79. );
  80. $form['#submit'][] = 'log_filter_admin_form_submit';
  81. return system_settings_form($form);
  82. }
  83. /**
  84. * @param array $form
  85. * @param array &$form_state
  86. * @return void
  87. */
  88. function _log_filter_admin_form_submit($form, &$form_state) {
  89. // Make form clear menu cache upon submission.
  90. if (!isset($_SESSION['module'])) {
  91. $_SESSION['module'] = array(
  92. 'log_filter' => array('admin_form_submitted' => TRUE),
  93. );
  94. }
  95. elseif (!isset($_SESSION['module']['log_filter'])) {
  96. $_SESSION['module']['log_filter'] = array('admin_form_submitted' => TRUE);
  97. }
  98. else {
  99. $_SESSION['module']['log_filter']['admin_form_submitted'] = TRUE;
  100. }
  101. $values =& $form_state['values'];
  102. $values['log_filter_pgrng'] = !($val = (int)trim($values['log_filter_pgrng'])) || $val < 0 ? LogFilter::PAGE_RANGE_DEFAULT :
  103. ($val > LogFilter::PAGE_RANGE_MAX ? LogFilter::PAGE_RANGE_MAX : $val);
  104. }