update.settings.inc

  1. drupal
    1. 6 modules/update/update.settings.inc
    2. 7 modules/update/update.settings.inc
    3. 8 core/modules/update/update.settings.inc

Code required only for the update status settings form.

Functions & methods

NameDescription
update_settingsForm builder for the update settings tab.
update_settings_submitSubmit handler for the settings tab.
update_settings_validateValidation callback for the settings form.

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 builder for the update settings tab.
  8. */
  9. function update_settings($form) {
  10. $form['update_check_frequency'] = array(
  11. '#type' => 'radios',
  12. '#title' => t('Check for updates'),
  13. '#default_value' => variable_get('update_check_frequency', 1),
  14. '#options' => array(
  15. '1' => t('Daily'),
  16. '7' => t('Weekly'),
  17. ),
  18. '#description' => t('Select how frequently you want to automatically check for new releases of your currently installed modules and themes.'),
  19. );
  20. $form['update_check_disabled'] = array(
  21. '#type' => 'checkbox',
  22. '#title' => t('Check for updates of disabled modules and themes'),
  23. '#default_value' => variable_get('update_check_disabled', FALSE),
  24. );
  25. $notify_emails = variable_get('update_notify_emails', array());
  26. $form['update_notify_emails'] = array(
  27. '#type' => 'textarea',
  28. '#title' => t('E-mail addresses to notify when updates are available'),
  29. '#rows' => 4,
  30. '#default_value' => implode("\n", $notify_emails),
  31. '#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.'),
  32. );
  33. $form['update_notification_threshold'] = array(
  34. '#type' => 'radios',
  35. '#title' => t('E-mail notification threshold'),
  36. '#default_value' => variable_get('update_notification_threshold', 'all'),
  37. '#options' => array(
  38. 'all' => t('All newer versions'),
  39. 'security' => t('Only security updates'),
  40. ),
  41. '#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')))
  42. );
  43. $form = system_settings_form($form);
  44. // Custom validation callback for the email notification setting.
  45. $form['#validate'][] = 'update_settings_validate';
  46. // We need to call our own submit callback first, not the one from
  47. // system_settings_form(), so that we can process and save the emails.
  48. unset($form['#submit']);
  49. return $form;
  50. }
  51. /**
  52. * Validation callback for the settings form.
  53. *
  54. * Validates the email addresses and ensures the field is formatted correctly.
  55. */
  56. function update_settings_validate($form, &$form_state) {
  57. if (!empty($form_state['values']['update_notify_emails'])) {
  58. $valid = array();
  59. $invalid = array();
  60. foreach (explode("\n", trim($form_state['values']['update_notify_emails'])) as $email) {
  61. $email = trim($email);
  62. if (!empty($email)) {
  63. if (valid_email_address($email)) {
  64. $valid[] = $email;
  65. }
  66. else {
  67. $invalid[] = $email;
  68. }
  69. }
  70. }
  71. if (empty($invalid)) {
  72. $form_state['notify_emails'] = $valid;
  73. }
  74. elseif (count($invalid) == 1) {
  75. form_set_error('update_notify_emails', t('%email is not a valid e-mail address.', array('%email' => reset($invalid))));
  76. }
  77. else {
  78. form_set_error('update_notify_emails', t('%emails are not valid e-mail addresses.', array('%emails' => implode(', ', $invalid))));
  79. }
  80. }
  81. }
  82. /**
  83. * Submit handler for the settings tab.
  84. *
  85. * Also invalidates the cache of available updates if the "Check for updates
  86. * of disabled modules and themes" setting is being changed. The available
  87. * updates report need to refetch available update data after this setting
  88. * changes or it would show misleading things (e.g. listing the disabled
  89. * projects on the site with the "No available releases found" warning).
  90. */
  91. function update_settings_submit($form, $form_state) {
  92. $op = $form_state['values']['op'];
  93. if (empty($form_state['notify_emails'])) {
  94. variable_del('update_notify_emails');
  95. }
  96. else {
  97. variable_set('update_notify_emails', $form_state['notify_emails']);
  98. }
  99. unset($form_state['notify_emails']);
  100. unset($form_state['values']['update_notify_emails']);
  101. // See if the update_check_disabled setting is being changed, and if so,
  102. // invalidate all cached update status data.
  103. $check_disabled = variable_get('update_check_disabled', FALSE);
  104. if ($form_state['values']['update_check_disabled'] != $check_disabled) {
  105. _update_cache_clear();
  106. }
  107. system_settings_form_submit($form, $form_state);
  108. }
Login or register to post comments