function nodeformsettings_form_alter in Node and Comments Form Settings 6.2
Same name and namespace in other branches
- 6.3 nodeformsettings.module \nodeformsettings_form_alter()
- 6 nodeformsettings.module \nodeformsettings_form_alter()
- 7.3 nodeformsettings.module \nodeformsettings_form_alter()
- 7.2 nodeformsettings.module \nodeformsettings_form_alter()
Implementation of hook_form_alter()
File
- ./
nodeformsettings.module, line 73 - main file, only one hook_form_alter to change several settings
Code
function nodeformsettings_form_alter(&$form, $form_state, $form_id) {
// When configuring the content type settings
if ($form_id == 'node_type_form') {
// get the path to the includes dir
$path = drupal_get_path("module", "nodeformsettings") . '/includes/';
// save the name of the variable for use in the submit callback
$form['var'] = array(
'#type' => 'hidden',
'#value' => $form['#node_type']->type,
);
// get the default settings using variable_get and the current content type
$settings = nodeformsettings_get_settings($form['#node_type']->type);
// load the settings
include_once $path . 'settings_node.inc';
// get the form with the settings
_nodeformsettings_settings_form($form, $settings);
// Validation callback
$form['#validate'][] = 'nodeformsettings_settings_validate';
// To save the values in an keyed array we need to define a custom submit callback
$form['#submit'][] = 'nodeformsettings_settings_submit';
}
// On node form (but not the node type admin form)
if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] . '_node_form' == $form_id && arg(0) != 'admin') {
$node = $form['#node'];
// get the path to the includes dir
$path = drupal_get_path("module", "nodeformsettings") . '/includes/';
// get the settings
$settings = nodeformsettings_get_settings($node->type);
// Get all the elements defined in the function
$elements = nodeformsettings_elements_default();
// Loop thought the array to build the function
foreach ($elements as $key => $vals) {
if (isset($settings[$key])) {
// Ignore the elements in the variable. We do this because in this particular case this change is not being made
// in a hook_form_alter, but a preprocess_page function, if we don't ignore it we'll get an error.
// If more changes are made out the hook_form_alter, then add those elements to this array.
$ignore = array(
"nfs_hide_node_title",
);
// If the $key is not in the array $ignore detect the functions
if (!in_array($key, $ignore)) {
include_once $path . 'option_' . $key . '.inc';
$function = '_option_' . $key;
if (function_exists($function)) {
$function($form, $form_state, $settings, $node);
}
}
}
}
}
}