update.settings.inc

You are here

  1. 7 modules/update/update.settings.inc
  2. 6 modules/update/update.settings.inc

Code required only for the update status settings form.

Functions

Namesort descending Description
update_settings Form constructor for the update settings form.
update_settings_submit Form submission handler for update_settings().
update_settings_validate Form validation handler for update_settings().

File

modules/update/update.settings.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Code required only for the update status settings form.
  5. */
  6. /**
  7. * Form constructor for the update settings form.
  8. *
  9. * @see update_settings_validate()
  10. * @see update_settings_submit()
  11. * @ingroup forms
  12. */
  13. function update_settings($form) {
  14. $form['update_check_frequency'] = array(
  15. '#type' => 'radios',
  16. '#title' => t('Check for updates'),
  17. '#default_value' => variable_get('update_check_frequency', 1),
  18. '#options' => array(
  19. '1' => t('Daily'),
  20. '7' => t('Weekly'),
  21. ),
  22. '#description' => t('Select how frequently you want to automatically check for new releases of your currently installed modules and themes.'),
  23. );
  24. $form['update_check_disabled'] = array(
  25. '#type' => 'checkbox',
  26. '#title' => t('Check for updates of disabled modules and themes'),
  27. '#default_value' => variable_get('update_check_disabled', FALSE),
  28. );
  29. $notify_emails = variable_get('update_notify_emails', array());
  30. $form['update_notify_emails'] = array(
  31. '#type' => 'textarea',
  32. '#title' => t('E-mail addresses to notify when updates are available'),
  33. '#rows' => 4,
  34. '#default_value' => implode("\n", $notify_emails),
  35. '#description' => t('Whenever your site checks for available updates and finds new releases, it can notify a list of users via e-mail. Put each address on a separate line. If blank, no e-mails will be sent.'),
  36. );
  37. $form['update_notification_threshold'] = array(
  38. '#type' => 'radios',
  39. '#title' => t('E-mail notification threshold'),
  40. '#default_value' => variable_get('update_notification_threshold', 'all'),
  41. '#options' => array(
  42. 'all' => t('All newer versions'),
  43. 'security' => t('Only security updates'),
  44. ),
  45. '#description' => t('You can choose to send e-mail only if a security update is available, or to be notified about all newer versions. If there are updates available of Drupal core or any of your installed modules and themes, your site will always print a message on the <a href="@status_report">status report</a> page, and will also display an error message on administration pages if there is a security update.', array('@status_report' => url('admin/reports/status')))
  46. );
  47. $form = system_settings_form($form);
  48. // Custom validation callback for the email notification setting.
  49. $form['#validate'][] = 'update_settings_validate';
  50. // We need to call our own submit callback first, not the one from
  51. // system_settings_form(), so that we can process and save the emails.
  52. unset($form['#submit']);
  53. return $form;
  54. }
  55. /**
  56. * Form validation handler for update_settings().
  57. *
  58. * Validates the e-mail addresses and ensures the field is formatted correctly.
  59. *
  60. * @see update_settings_submit()
  61. */
  62. function update_settings_validate($form, &$form_state) {
  63. if (!empty($form_state['values']['update_notify_emails'])) {
  64. $valid = array();
  65. $invalid = array();
  66. foreach (explode("\n", trim($form_state['values']['update_notify_emails'])) as $email) {
  67. $email = trim($email);
  68. if (!empty($email)) {
  69. if (valid_email_address($email)) {
  70. $valid[] = $email;
  71. }
  72. else {
  73. $invalid[] = $email;
  74. }
  75. }
  76. }
  77. if (empty($invalid)) {
  78. $form_state['notify_emails'] = $valid;
  79. }
  80. elseif (count($invalid) == 1) {
  81. form_set_error('update_notify_emails', t('%email is not a valid e-mail address.', array('%email' => reset($invalid))));
  82. }
  83. else {
  84. form_set_error('update_notify_emails', t('%emails are not valid e-mail addresses.', array('%emails' => implode(', ', $invalid))));
  85. }
  86. }
  87. }
  88. /**
  89. * Form submission handler for update_settings().
  90. *
  91. * Also invalidates the cache of available updates if the "Check for updates of
  92. * disabled modules and themes" setting is being changed. The available updates
  93. * report needs to refetch available update data after this setting changes or
  94. * it would show misleading things (e.g., listing the disabled projects on the
  95. * site with the "No available releases found" warning).
  96. *
  97. * @see update_settings_validate()
  98. */
  99. function update_settings_submit($form, $form_state) {
  100. $op = $form_state['values']['op'];
  101. if (empty($form_state['notify_emails'])) {
  102. variable_del('update_notify_emails');
  103. }
  104. else {
  105. variable_set('update_notify_emails', $form_state['notify_emails']);
  106. }
  107. unset($form_state['notify_emails']);
  108. unset($form_state['values']['update_notify_emails']);
  109. // See if the update_check_disabled setting is being changed, and if so,
  110. // invalidate all cached update status data.
  111. $check_disabled = variable_get('update_check_disabled', FALSE);
  112. if ($form_state['values']['update_check_disabled'] != $check_disabled) {
  113. _update_cache_clear();
  114. }
  115. system_settings_form_submit($form, $form_state);
  116. }