diff options
Diffstat (limited to 'modules/shortcut/shortcut.admin.inc')
-rw-r--r-- | modules/shortcut/shortcut.admin.inc | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/modules/shortcut/shortcut.admin.inc b/modules/shortcut/shortcut.admin.inc index e86d8f50f..27384a669 100644 --- a/modules/shortcut/shortcut.admin.inc +++ b/modules/shortcut/shortcut.admin.inc @@ -33,6 +33,7 @@ function shortcut_max_slots() { * An array representing the form definition. * * @ingroup forms + * @see shortcut_set_switch_validate() * @see shortcut_set_switch_submit() */ function shortcut_set_switch($form, &$form_state, $account = NULL) { @@ -102,6 +103,22 @@ function shortcut_set_switch($form, &$form_state, $account = NULL) { } /** + * Validation handler for shortcut_set_switch(). + */ +function shortcut_set_switch_validate($form, &$form_state) { + if ($form_state['values']['set'] == 'new') { + // Check to prevent creating a shortcut set with an empty title. + if (trim($form_state['values']['new']) == '') { + form_set_error('new', t('The new set name is required.')); + } + // Check to prevent a duplicate title. + if (shortcut_set_title_exists($form_state['values']['new'])) { + form_set_error('new', t('The shortcut set %name already exists. Choose another name.', array('%name' => $form_state['values']['new']))); + } + } +} + +/** * Submit handler for shortcut_set_switch(). */ function shortcut_set_switch_submit($form, &$form_state) { @@ -184,6 +201,7 @@ function shortcut_set_admin() { * An array representing the form definition. * * @ingroup forms + * @see shortcut_set_add_form_validate() * @see shortcut_set_add_form_submit() */ function shortcut_set_add_form($form, &$form_state) { @@ -191,6 +209,7 @@ function shortcut_set_add_form($form, &$form_state) { '#type' => 'textfield', '#title' => t('Set name'), '#description' => t('The new set is created by copying items from your default shortcut set.'), + '#required' => TRUE, ); $form['actions'] = array('#type' => 'actions'); @@ -203,6 +222,16 @@ function shortcut_set_add_form($form, &$form_state) { } /** + * Validation handler for shortcut_set_add_form(). + */ +function shortcut_set_add_form_validate($form, &$form_state) { + // Check to prevent a duplicate title. + if (shortcut_set_title_exists($form_state['values']['new'])) { + form_set_error('new', t('The shortcut set %name already exists. Choose another name.', array('%name' => $form_state['values']['new']))); + } +} + +/** * Submit handler for shortcut_set_add_form(). */ function shortcut_set_add_form_submit($form, &$form_state) { @@ -547,6 +576,7 @@ function shortcut_admin_add_link($shortcut_link, &$shortcut_set, $limit = NULL) * An array representing the form definition. * * @ingroup forms + * @see shortcut_set_edit_form_validate() * @see shortcut_set_edit_form_submit() */ function shortcut_set_edit_form($form, &$form_state, $shortcut_set) { @@ -573,6 +603,17 @@ function shortcut_set_edit_form($form, &$form_state, $shortcut_set) { } /** + * Validation handler for shortcut_set_edit_form(). + */ +function shortcut_set_edit_form_validate($form, &$form_state) { + // Check to prevent a duplicate title, if the title was edited from its + // original value. + if ($form_state['values']['title'] != $form_state['values']['shortcut_set']->title && shortcut_set_title_exists($form_state['values']['title'])) { + form_set_error('title', t('The shortcut set %name already exists. Choose another name.', array('%name' => $form_state['values']['title']))); + } +} + +/** * Submit handler for shortcut_set_edit_form(). */ function shortcut_set_edit_form_submit($form, &$form_state) { |