function csm_form_alter in Custom Submit Messages 7
Same name and namespace in other branches
- 6 csm.module \csm_form_alter()
Implements hook_form_alter().
File
- ./
csm.module, line 182 - The main module file for Custom Submit Messages.
Code
function csm_form_alter(&$form, $form_state, $form_id) {
// Need an if clause to stop errors occurring when a value isn't set
if (!isset($form['type']['#value'])) {
return;
}
// Need another if clause so that we exit if this isn't the sort of form we
// care about
if (!($form_id == $form['type']['#value'] . '_node_form' && $form['nid']['#value'] == NULL && empty($form_state['post']))) {
return;
}
global $language;
global $user;
$relevant_roles = _csm_relevant_role_array($user);
$csm_settings = variable_get('csm_attributes', NULL);
// Is there a way of combining these two foreach loops?
foreach ($relevant_roles as $key => $role) {
// If the title is set for that role, use that title
$title = variable_get('csm_form_title_' . $language->language . '_' . $role . '_' . $form['type']['#value'], '');
if ($title && $title !== '') {
if ($title == '<none>') {
$title = '';
}
drupal_set_title(token_replace($title, array(
'node' => $form['#node'],
)));
// Log a system message.
watchdog('csm', '@type: node creation page title changed using Custom
Submit Messages.', array(
'@type' => $form['type']['#value'],
), WATCHDOG_NOTICE);
break;
}
}
reset($relevant_roles);
foreach ($relevant_roles as $key => $role) {
// If the message is set for that role, use that message
$message = variable_get('csm_form_msg_msg_' . $language->language . '_' . $role . '_' . $form['type']['#value'], '');
if ($message && $message !== '') {
// The message is set
$message_type = variable_get('csm_form_msg_type_' . $language->language . '_' . $role . '_' . $form['type']['#value'], 'status');
if ($message_type == 'none') {
// The message is set, but the message type is set to "none". We need to
// keep looking for a message to set.
continue;
}
else {
drupal_set_message(check_plain(token_replace($message, array(
'node' => $form['#node'],
))), $message_type);
// Log a system message
watchdog('csm', '@type: node creation page message set using Custom
Submit Messages.', array(
'@type' => $form['type']['#value'],
), WATCHDOG_NOTICE);
break;
}
}
}
return;
}