summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngie Byron2009-01-22 03:11:54 (GMT)
committerAngie Byron2009-01-22 03:11:54 (GMT)
commitb4c737a2a5ed9bf9905c91107f94e42df36f2c44 (patch)
tree8bed38a803bf4f1c8dc1e657f42abe9cc2fd952d
parent7ac380aa059bd901e7965445080d2fddef84f9e9 (diff)
#287178 by justinrandell: Break up various hook_form_alter()s to hook_form_FORM_ID_alters().
-rw-r--r--modules/color/color.module38
-rw-r--r--modules/comment/comment.module14
-rw-r--r--modules/locale/locale.module87
-rw-r--r--modules/node/node.module8
-rw-r--r--modules/openid/openid.module88
-rw-r--r--modules/translation/translation.module20
-rw-r--r--modules/update/update.module20
7 files changed, 161 insertions, 114 deletions
diff --git a/modules/color/color.module b/modules/color/color.module
index 50006af..fa53f45 100644
--- a/modules/color/color.module
+++ b/modules/color/color.module
@@ -28,11 +28,10 @@ function color_theme() {
}
/**
- * Implementation of hook_form_alter().
+ * Implementation of hook_form_FORM_ID_alter().
*/
-function color_form_alter(&$form, $form_state, $form_id) {
- // Insert the color changer into the theme settings page.
- if ($form_id == 'system_theme_settings' && color_get_info(arg(4)) && function_exists('gd_info')) {
+function color_form_system_theme_settings_alter(&$form, &$form_state) {
+ if (color_get_info(arg(4)) && function_exists('gd_info')) {
if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) != FILE_DOWNLOADS_PUBLIC) {
// Disables the color changer when the private download method is used.
// TODO: This should be solved in a different way. See issue #181003.
@@ -50,15 +49,32 @@ function color_form_alter(&$form, $form_state, $form_id) {
$form['#submit'][] = 'color_scheme_form_submit';
}
}
+}
+/**
+ * Implementation of hook_form_FORM_ID_alter().
+ */
+function color_form_system_themes_alter(&$form, &$form_state) {
+ _color_theme_select_form_alter($form, $form_state);
+}
+
+/**
+ * Implementation of hook_form_FORM_ID_alter().
+ */
+function color_form_system_theme_select_form_alter(&$form, &$form_state) {
+ _color_theme_select_form_alter($form, $form_state);
+}
+
+/**
+ * Helper for hook_form_FORM_ID_alter() implementations.
+ */
+function _color_theme_select_form_alter(&$form, &$form_state) {
// Use the generated screenshot in the theme list.
- if ($form_id == 'system_theme_select_form' || $form_id == 'system_themes') {
- $themes = list_themes();
- foreach (element_children($form) as $theme) {
- if ($screenshot = variable_get('color_' . $theme . '_screenshot', NULL)) {
- if (isset($form[$theme]['screenshot'])) {
- $form[$theme]['screenshot']['#markup'] = theme('image', $screenshot, '', '', array('class' => 'screenshot'), FALSE);
- }
+ $themes = list_themes();
+ foreach (element_children($form) as $theme) {
+ if ($screenshot = variable_get('color_' . $theme . '_screenshot', NULL)) {
+ if (isset($form[$theme]['screenshot'])) {
+ $form[$theme]['screenshot']['#markup'] = theme('image', $screenshot, '', '', array('class' => 'screenshot'), FALSE);
}
}
}
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index 45cad76..951ac3c 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -504,10 +504,10 @@ function comment_nodeapi_view($node, $teaser) {
}
/**
- * Implementation of hook_form_alter().
+ * Implementation of hook_form_FORM_ID_alter().
*/
-function comment_form_alter(&$form, $form_state, $form_id) {
- if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
+function comment_form_node_type_form_alter(&$form, $form_state) {
+ if (isset($form['identity']['type'])) {
$form['comment'] = array(
'#type' => 'fieldset',
'#title' => t('Comment settings'),
@@ -571,7 +571,13 @@ function comment_form_alter(&$form, $form_state, $form_id) {
'#options' => array(t('Display on separate page'), t('Display below post or comments')),
);
}
- elseif (!empty($form['#node_edit_form'])) {
+}
+
+/**
+ * Implementation of hook_form_alter().
+ */
+function comment_form_alter(&$form, $form_state, $form_id) {
+ if (!empty($form['#node_edit_form'])) {
$node = $form['#node'];
$form['comment_settings'] = array(
'#type' => 'fieldset',
diff --git a/modules/locale/locale.module b/modules/locale/locale.module
index 7fa66b3..71c2959 100644
--- a/modules/locale/locale.module
+++ b/modules/locale/locale.module
@@ -254,56 +254,55 @@ function locale_language_selector_form($user) {
}
/**
- * Implementation of hook_form_alter(). Adds language fields to forms.
+ * Implementation of hook_form_FORM_ID_alter().
+ */
+function locale_form_path_admin_form_alter(&$form, &$form_state) {
+ $form['language'] = array(
+ '#type' => 'select',
+ '#title' => t('Language'),
+ '#options' => array('' => t('All languages')) + locale_language_list('name'),
+ '#default_value' => $form['language']['#value'],
+ '#weight' => -10,
+ '#description' => t('A path alias set for a specific language will always be used when displaying this page in that language, and takes precedence over path aliases set for <em>All languages</em>.'),
+ );
+}
+
+/**
+ * Implementation of hook_form_FORM_ID_alter().
*/
-function locale_form_alter(&$form, $form_state, $form_id) {
- switch ($form_id) {
+function locale_form_node_type_form_alter(&$form, &$form_state) {
+ if (isset($form['identity']['type'])) {
+ $form['workflow']['language_content_type'] = array(
+ '#type' => 'radios',
+ '#title' => t('Multilingual support'),
+ '#default_value' => variable_get('language_content_type_' . $form['#node_type']->type, 0),
+ '#options' => array(t('Disabled'), t('Enabled')),
+ '#description' => t('Enable multilingual support for this content type. If enabled, a language selection field will be added to the editing form, allowing you to select from one of the <a href="!languages">enabled languages</a>. If disabled, new posts are saved with the default language. Existing content will not be affected by changing this option.', array('!languages' => url('admin/settings/language'))),
+ );
+ }
+}
- // Language field for paths
- case 'path_admin_form':
+/**
+ * Implementation of hook_form_alter(). Adds language fields to forms.
+ */
+function locale_form_alter(&$form, &$form_state, $form_id) {
+ if (isset($form['#id']) && $form['#id'] == 'node-form') {
+ if (isset($form['#node']->type) && variable_get('language_content_type_' . $form['#node']->type, 0)) {
$form['language'] = array(
'#type' => 'select',
'#title' => t('Language'),
- '#options' => array('' => t('All languages')) + locale_language_list('name'),
- '#default_value' => $form['language']['#value'],
- '#weight' => -10,
- '#description' => t('A path alias set for a specific language will always be used when displaying this page in that language, and takes precedence over path aliases set for <em>All languages</em>.'),
+ '#default_value' => (isset($form['#node']->language) ? $form['#node']->language : ''),
+ '#options' => array('' => t('Language neutral')) + locale_language_list('name'),
);
- break;
-
- // Language setting for content types
- case 'node_type_form':
- if (isset($form['identity']['type'])) {
- $form['workflow']['language_content_type'] = array(
- '#type' => 'radios',
- '#title' => t('Multilingual support'),
- '#default_value' => variable_get('language_content_type_' . $form['#node_type']->type, 0),
- '#options' => array(t('Disabled'), t('Enabled')),
- '#description' => t('Enable multilingual support for this content type. If enabled, a language selection field will be added to the editing form, allowing you to select from one of the <a href="!languages">enabled languages</a>. If disabled, new posts are saved with the default language. Existing content will not be affected by changing this option.', array('!languages' => url('admin/settings/language'))),
- );
- }
- break;
-
- // Language field for nodes
- default:
- if (isset($form['#id']) && $form['#id'] == 'node-form') {
- if (isset($form['#node']->type) && variable_get('language_content_type_' . $form['#node']->type, 0)) {
- $form['language'] = array(
- '#type' => 'select',
- '#title' => t('Language'),
- '#default_value' => (isset($form['#node']->language) ? $form['#node']->language : ''),
- '#options' => array('' => t('Language neutral')) + locale_language_list('name'),
- );
- }
- // Node type without language selector: assign the default for new nodes
- elseif (!isset($form['#node']->nid)) {
- $default = language_default();
- $form['language'] = array(
- '#type' => 'value',
- '#value' => $default->language
- );
- }
- }
+ }
+ // Node type without language selector: assign the default for new nodes
+ elseif (!isset($form['#node']->nid)) {
+ $default = language_default();
+ $form['language'] = array(
+ '#type' => 'value',
+ '#value' => $default->language
+ );
+ }
}
}
diff --git a/modules/node/node.module b/modules/node/node.module
index 068813f..25e10df 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -1989,11 +1989,10 @@ function _node_index_node($node) {
}
/**
- * Implementation of hook_form_alter().
+ * Implementation of hook_form_FORM_ID_alter().
*/
-function node_form_alter(&$form, $form_state, $form_id) {
- // Advanced node search form
- if ($form_id == 'search_form' && $form['module']['#value'] == 'node' && user_access('use advanced search')) {
+function node_form_search_form_alter(&$form, $form_state) {
+ if ($form['module']['#value'] == 'node' && user_access('use advanced search')) {
// Keyword boxes:
$form['advanced'] = array(
'#type' => 'fieldset',
@@ -2069,7 +2068,6 @@ function node_form_alter(&$form, $form_state, $form_id) {
);
}
-
$form['#validate'][] = 'node_search_validate';
}
}
diff --git a/modules/openid/openid.module b/modules/openid/openid.module
index cf5681b..a058f4e 100644
--- a/modules/openid/openid.module
+++ b/modules/openid/openid.module
@@ -71,47 +71,62 @@ function openid_user_insert(&$edit, &$account, $category = NULL) {
}
/**
- * Implementation of hook_form_alter(). Adds OpenID login to the login forms.
+ * Implementation of hook_form_FORM_ID_alter().
*/
-function openid_form_alter(&$form, $form_state, $form_id) {
- if ($form_id == 'user_login_block' || $form_id == 'user_login') {
- drupal_add_css(drupal_get_path('module', 'openid') . '/openid.css');
- drupal_add_js(drupal_get_path('module', 'openid') . '/openid.js');
- if (!empty($form_state['post']['openid_identifier'])) {
- $form['name']['#required'] = FALSE;
- $form['pass']['#required'] = FALSE;
- unset($form['#submit']);
- $form['#validate'] = array('openid_login_validate');
- }
+function openid_form_user_login_block_alter(&$form, &$form_state) {
+ _openid_user_login_form_alter($form, $form_state);
+}
- $items = array();
- $items[] = array(
- 'data' => l(t('Log in using OpenID'), '#'),
- 'class' => 'openid-link',
- );
- $items[] = array(
- 'data' => l(t('Cancel OpenID login'), '#'),
- 'class' => 'user-link',
- );
+/**
+ * Implementation of hook_form_FORM_ID_alter().
+ */
+function openid_form_user_login_alter(&$form, &$form_state) {
+ _openid_user_login_form_alter($form, $form_state);
+}
- $form['openid_links'] = array(
- '#markup' => theme('item_list', $items),
- '#weight' => 1,
- );
+function _openid_user_login_form_alter(&$form, &$form_state) {
+ drupal_add_css(drupal_get_path('module', 'openid') . '/openid.css');
+ drupal_add_js(drupal_get_path('module', 'openid') . '/openid.js');
+ if (!empty($form_state['post']['openid_identifier'])) {
+ $form['name']['#required'] = FALSE;
+ $form['pass']['#required'] = FALSE;
+ unset($form['#submit']);
+ $form['#validate'] = array('openid_login_validate');
+ }
- $form['links']['#weight'] = 2;
+ $items = array();
+ $items[] = array(
+ 'data' => l(t('Log in using OpenID'), '#'),
+ 'class' => 'openid-link',
+ );
+ $items[] = array(
+ 'data' => l(t('Cancel OpenID login'), '#'),
+ 'class' => 'user-link',
+ );
- $form['openid_identifier'] = array(
- '#type' => 'textfield',
- '#title' => t('Log in using OpenID'),
- '#size' => ($form_id == 'user_login') ? 58 : 13,
- '#maxlength' => 255,
- '#weight' => -1,
- '#description' => l(t('What is OpenID?'), 'http://openid.net/', array('external' => TRUE)),
- );
- $form['openid.return_to'] = array('#type' => 'hidden', '#value' => url('openid/authenticate', array('absolute' => TRUE, 'query' => drupal_get_destination())));
- }
- elseif ($form_id == 'user_register' && isset($_SESSION['openid'])) {
+ $form['openid_links'] = array(
+ '#markup' => theme('item_list', $items),
+ '#weight' => 1,
+ );
+
+ $form['links']['#weight'] = 2;
+
+ $form['openid_identifier'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Log in using OpenID'),
+ '#size' => ($form_id == 'user_login') ? 58 : 13,
+ '#maxlength' => 255,
+ '#weight' => -1,
+ '#description' => l(t('What is OpenID?'), 'http://openid.net/', array('external' => TRUE)),
+ );
+ $form['openid.return_to'] = array('#type' => 'hidden', '#value' => url('openid/authenticate', array('absolute' => TRUE, 'query' => drupal_get_destination())));
+}
+
+/**
+ * Implementation of hook_form_alter(). Adds OpenID login to the login forms.
+ */
+function openid_form_user_register_alter(&$form, &$form_state) {
+ if (isset($_SESSION['openid'])) {
// We were unable to auto-register a new user. Prefill the registration
// form with the values we have.
$form['name']['#default_value'] = $_SESSION['openid']['values']['name'];
@@ -124,7 +139,6 @@ function openid_form_alter(&$form, $form_state, $form_id) {
}
$form['auth_openid'] = array('#type' => 'hidden', '#value' => $_SESSION['openid']['values']['auth_openid']);
}
- return $form;
}
/**
diff --git a/modules/translation/translation.module b/modules/translation/translation.module
index 0057dfb..35fe825 100644
--- a/modules/translation/translation.module
+++ b/modules/translation/translation.module
@@ -94,20 +94,24 @@ function translation_perm() {
}
/**
+ * Implementation of hook_form_FORM_ID_alter().
+ */
+function translation_form_node_type_form_alter(&$form, &$form_state) {
+ // Add translation option to content type form.
+ $form['workflow']['language_content_type']['#options'][TRANSLATION_ENABLED] = t('Enabled, with translation');
+ // Description based on text from locale.module.
+ $form['workflow']['language_content_type']['#description'] = t('Enable multilingual support for this content type. If enabled, a language selection field will be added to the editing form, allowing you to select from one of the <a href="!languages">enabled languages</a>. You can also turn on translation for this content type, which lets you have content translated to any of the enabled languages. If disabled, new posts are saved with the default language. Existing content will not be affected by changing this option.', array('!languages' => url('admin/settings/language')));
+}
+
+/**
* Implementation of hook_form_alter().
*
* - Add translation option to content type form.
* - Alters language fields on node forms when a translation
* is about to be created.
*/
-function translation_form_alter(&$form, $form_state, $form_id) {
- if ($form_id == 'node_type_form') {
- // Add translation option to content type form.
- $form['workflow']['language_content_type']['#options'][TRANSLATION_ENABLED] = t('Enabled, with translation');
- // Description based on text from locale.module.
- $form['workflow']['language_content_type']['#description'] = t('Enable multilingual support for this content type. If enabled, a language selection field will be added to the editing form, allowing you to select from one of the <a href="!languages">enabled languages</a>. You can also turn on translation for this content type, which lets you have content translated to any of the enabled languages. If disabled, new posts are saved with the default language. Existing content will not be affected by changing this option.', array('!languages' => url('admin/settings/language')));
- }
- elseif (isset($form['#id']) && $form['#id'] == 'node-form' && translation_supported_type($form['#node']->type)) {
+function translation_form_alter(&$form, &$form_state, $form_id) {
+ if (isset($form['#id']) && $form['#id'] == 'node-form' && translation_supported_type($form['#node']->type)) {
$node = $form['#node'];
if (!empty($node->translation_source)) {
// We are creating a translation. Add values and lock language field.
diff --git a/modules/update/update.module b/modules/update/update.module
index 8952f6e..d103f04 100644
--- a/modules/update/update.module
+++ b/modules/update/update.module
@@ -286,17 +286,27 @@ function update_cron() {
}
/**
- * Implementation of hook_form_alter().
+ * Implementation of hook_form_FORM_ID_alter().
*
* Adds a submit handler to the system modules and themes forms, so that if a
* site admin saves either form, we invalidate the cache of available updates.
*
* @see update_invalidate_cache()
*/
-function update_form_alter(&$form, $form_state, $form_id) {
- if ($form_id == 'system_modules' || $form_id == 'system_themes' ) {
- $form['#submit'][] = 'update_invalidate_cache';
- }
+function update_form_system_themes_alter(&$form, $form_state) {
+ $form['#submit'][] = 'update_invalidate_cache';
+}
+
+/**
+ * Implementation of hook_form_FORM_ID_alter().
+ *
+ * Adds a submit handler to the system modules and themes forms, so that if a
+ * site admin saves either form, we invalidate the cache of available updates.
+ *
+ * @see update_invalidate_cache()
+ */
+function update_form_system_modules_alter(&$form, $form_state) {
+ $form['#submit'][] = 'update_invalidate_cache';
}
/**