#287178 by justinrandell: Break up various hook_form_alter()s to hook_form_FORM_ID_alters().
parent
7ac380aa05
commit
b4c737a2a5
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -253,57 +253,56 @@ function locale_language_selector_form($user) {
|
|||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_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'))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_form_alter(). Adds language fields to forms.
|
||||
*/
|
||||
function locale_form_alter(&$form, $form_state, $form_id) {
|
||||
switch ($form_id) {
|
||||
|
||||
// Language field for paths
|
||||
case 'path_admin_form':
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,48 +70,63 @@ function openid_user_insert(&$edit, &$account, $category = NULL) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_form_FORM_ID_alter().
|
||||
*/
|
||||
function openid_form_user_login_block_alter(&$form, &$form_state) {
|
||||
_openid_user_login_form_alter($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_form_FORM_ID_alter().
|
||||
*/
|
||||
function openid_form_user_login_alter(&$form, &$form_state) {
|
||||
_openid_user_login_form_alter($form, $form_state);
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
$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_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_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');
|
||||
}
|
||||
|
||||
$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_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())));
|
||||
}
|
||||
elseif ($form_id == 'user_register' && isset($_SESSION['openid'])) {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -93,6 +93,16 @@ 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().
|
||||
*
|
||||
|
@ -100,14 +110,8 @@ function translation_perm() {
|
|||
* - 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.
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue