function _site_disclaimer_admin_decode_settings in Site Disclaimer 6
Same name and namespace in other branches
- 7 site_disclaimer.admin.inc \_site_disclaimer_admin_decode_settings()
Multiple-use function to process settings for:
- initial settings form build
- settings form validation
- settings form rebuild (as part of '#ajax' process)
2 calls to _site_disclaimer_admin_decode_settings()
- site_disclaimer_admin_settings in ./
site_disclaimer.admin.inc - Menu callback; show settings form.
- site_disclaimer_admin_settings_validate in ./
site_disclaimer.admin.inc - Validate the site_disclaimer_admin_settings form.
File
- ./
site_disclaimer.admin.inc, line 38 - Administration settings for Site Disclaimer module.
Code
function _site_disclaimer_admin_decode_settings(&$form_state, $validate = FALSE) {
$form_state += array(
'values' => array(),
);
$form_state += array(
'storage' => array(),
);
// D6 AHAH helper way
$is_form_submitted = !empty($form_state['values']['op']);
$orig_mode = isset($form_state['storage']['#site_disclaimer_mode']) ? $form_state['storage']['#site_disclaimer_mode'] : (isset($form_state['values']['site_disclaimer_node_id']) ? 'node_id' : 'node_title');
$mode = $orig_mode;
$form_state['storage']['#site_disclaimer_mode_switch'] = FALSE;
if ($is_form_submitted) {
if ($form_state['values']['op'] == SITE_DISCLAIMER_NODE_ID) {
$mode = 'node_id';
$form_state['storage']['#site_disclaimer_mode_switch'] = $mode;
}
elseif ($form_state['values']['op'] == SITE_DISCLAIMER_NODE_TITLE) {
$mode = 'node_title';
$form_state['storage']['#site_disclaimer_mode_switch'] = $mode;
}
if (!$validate) {
// Ignore the switch while validating
$mode = $orig_mode;
}
}
if (!$is_form_submitted && !$validate) {
// Start the form in preferred node title mode
$mode = 'node_title';
}
$form_state['storage']['#site_disclaimer_mode'] = $mode;
$title = '';
$nid = '';
if ($orig_mode == 'node_title') {
if (!$is_form_submitted) {
$title = variable_get('site_disclaimer_node_title', '');
}
elseif (!empty($form_state['values']['site_disclaimer_node_title'])) {
$title = $form_state['values']['site_disclaimer_node_title'];
}
if (!empty($title)) {
$node = node_load(array(
'title' => $title,
));
if (empty($node)) {
if ($is_form_submitted) {
form_set_error('site_disclaimer_node_title', t('No post was found with "!title" title.', array(
'!title' => $title,
)));
}
}
else {
$nid = $node->nid;
}
}
}
else {
// $orig_mode == 'node_id'
if (!$is_form_submitted) {
$nid = variable_get('site_disclaimer_node_id', '');
}
elseif (!empty($form_state['values']['site_disclaimer_node_id'])) {
$nid = $form_state['values']['site_disclaimer_node_id'];
}
if (!empty($nid)) {
$node = node_load($nid);
if (empty($node)) {
if ($is_form_submitted) {
form_set_error('site_disclaimer_node_id', t('No post was found with nid !nid.', array(
'!nid' => $nid,
)));
}
}
else {
$title = $node->title;
}
}
}
$form_state['values']['site_disclaimer_node_title'] = $title;
$form_state['values']['site_disclaimer_node_id'] = $nid;
$form_state['storage']['#site_disclaimer_nid'] = $nid;
}