/[drupal]/drupal/modules/update/update.settings.inc
ViewVC logotype

Contents of /drupal/modules/update/update.settings.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.9 - (show annotations) (download) (as text)
Fri Sep 18 00:12:48 2009 UTC (2 months, 1 week ago) by webchick
Branch: MAIN
CVS Tags: DRUPAL-7-0-UNSTABLE-10, HEAD
Changes since 1.8: +2 -4 lines
File MIME type: text/x-php
#571086 by sun and merlinofchaos: Added a 'wrapper callback' that executes
before a form builder function, to facilitate common form elements. Clean-up
from form_builder changes from CTools patch. Has nice side-benefit of making
all form functions' signatures consistent.
1 <?php
2 // $Id: update.settings.inc,v 1.8 2009/08/24 00:42:34 webchick Exp $
3
4 /**
5 * @file
6 * Code required only for the update status settings form.
7 */
8
9 /**
10 * Form builder for the update settings tab.
11 */
12 function update_settings($form) {
13 $notify_emails = variable_get('update_notify_emails', array());
14 $form['update_notify_emails'] = array(
15 '#type' => 'textarea',
16 '#title' => t('E-mail addresses to notify when updates are available'),
17 '#rows' => 4,
18 '#default_value' => implode("\n", $notify_emails),
19 '#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.'),
20 );
21
22 $form['update_check_frequency'] = array(
23 '#type' => 'radios',
24 '#title' => t('Check for updates'),
25 '#default_value' => variable_get('update_check_frequency', 1),
26 '#options' => array(
27 '1' => t('Daily'),
28 '7' => t('Weekly'),
29 ),
30 '#description' => t('Select how frequently you want to automatically check for new releases of your currently installed modules and themes.'),
31 );
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
44 $form['update_check_disabled'] = array(
45 '#type' => 'checkbox',
46 '#title' => t('Check for updates of disabled modules and themes'),
47 '#default_value' => variable_get('update_check_disabled', FALSE),
48 );
49
50 $form = system_settings_form($form, FALSE);
51 // Custom validation callback for the email notification setting.
52 $form['#validate'][] = 'update_settings_validate';
53 // We need to call our own submit callback first, not the one from
54 // system_settings_form(), so that we can process and save the emails.
55 unset($form['#submit']);
56
57 return $form;
58 }
59
60 /**
61 * Validation callback for the settings form.
62 *
63 * Validates the email addresses and ensures the field is formatted correctly.
64 */
65 function update_settings_validate($form, &$form_state) {
66 if (!empty($form_state['values']['update_notify_emails'])) {
67 $valid = array();
68 $invalid = array();
69 foreach (explode("\n", trim($form_state['values']['update_notify_emails'])) as $email) {
70 $email = trim($email);
71 if (!empty($email)) {
72 if (valid_email_address($email)) {
73 $valid[] = $email;
74 }
75 else {
76 $invalid[] = $email;
77 }
78 }
79 }
80 if (empty($invalid)) {
81 $form_state['notify_emails'] = $valid;
82 }
83 elseif (count($invalid) == 1) {
84 form_set_error('update_notify_emails', t('%email is not a valid e-mail address.', array('%email' => reset($invalid))));
85 }
86 else {
87 form_set_error('update_notify_emails', t('%emails are not valid e-mail addresses.', array('%emails' => implode(', ', $invalid))));
88 }
89 }
90 }
91
92 /**
93 * Submit handler for the settings tab.
94 *
95 * Also invalidates the cache of available updates if the "Check for updates
96 * of disabled modules and themes" setting is being changed. The available
97 * updates report need to refetch available update data after this setting
98 * changes or it would show misleading things (e.g. listing the disabled
99 * projects on the site with the "No available releases found" warning).
100 */
101 function update_settings_submit($form, $form_state) {
102 $op = $form_state['values']['op'];
103
104 if (empty($form_state['notify_emails'])) {
105 variable_del('update_notify_emails');
106 }
107 else {
108 variable_set('update_notify_emails', $form_state['notify_emails']);
109 }
110 unset($form_state['notify_emails']);
111 unset($form_state['values']['update_notify_emails']);
112
113 // See if the update_check_disabled setting is being changed, and if so,
114 // invalidate all cached update status data.
115 $check_disabled = variable_get('update_check_disabled', FALSE);
116 if ($form_state['values']['update_check_disabled'] != $check_disabled) {
117 _update_cache_clear();
118 }
119
120 system_settings_form_submit($form, $form_state);
121 }

  ViewVC Help
Powered by ViewVC 1.1.2