function workbench_email_form_node_form_alter in Workbench Email 7
Same name and namespace in other branches
- 7.3 workbench_email.form.inc \workbench_email_form_node_form_alter()
Implements hook_node_form_alter().
Determines the current state and next state. Depending on that criteria builds a form element(s) to allow the user to select users to send an email to.
Parameters
array $form: The form array
array $form_state: The form_state array
File
- ./
workbench_email.module, line 106 - Code for the Workbench Email Module.
Code
function workbench_email_form_node_form_alter(&$form, $form_state) {
if (workbench_moderation_node_type_moderated($form['type']['#value'])) {
$available = FALSE;
// Workbench Moderation uses "options" fieldset in favor of "revision information"
// if "administer roles" perm is given to content moderator.
if (isset($form['revision_information']['workbench_moderation_state_new'])) {
$wrapper_id = 'revision_information';
$available = TRUE;
}
else {
if (isset($form['options']['workbench_moderation_state_new'])) {
$wrapper_id = 'options';
$available = TRUE;
}
}
if (!$available) {
return;
}
$form[$wrapper_id]['workbench_moderation_state_new']['#ajax'] = array(
'callback' => 'workbench_email_form_node_callback',
'wrapper' => 'wv-workflow-form-node',
'effect' => 'fade',
'event' => 'change',
);
$form[$wrapper_id]['workflow_email'] = array(
'#prefix' => '<div id="wv-workflow-form-node">',
'#suffix' => '</div>',
'#tree' => TRUE,
);
// Determine current state.
if (isset($form['#node']->workbench_moderation['current']->state)) {
$current_from_state = $form['#node']->workbench_moderation['current']->state;
}
else {
$current_from_state = variable_get('workbench_moderation_default_state_' . $form['type']['#value'], workbench_moderation_state_none());
}
if ($current_from_state == workbench_moderation_state_published()) {
$current_from_state = workbench_moderation_state_none();
}
// Initialize to the current state.
$form_moderation_state = $current_from_state;
if (empty($form_state['values'])) {
$form_moderation_state = $current_from_state;
}
if (!empty($form_state['values']) && isset($form_state['values']['workbench_moderation_state_new'])) {
$form_moderation_state = $form_state['values']['workbench_moderation_state_new'];
}
if (!empty($form_state['values']) && isset($form_state['values'][$wrapper_id]['workbench_moderation_state_new'])) {
$form_moderation_state = $form_state['values'][$wrapper_id]['workbench_moderation_state_new'];
}
$workbench_emails = workbench_email_get();
foreach ($workbench_emails as $transition => $email_roles) {
foreach ($email_roles as $rid => $email_transition) {
if ($email_transition->from_name == $current_from_state && $email_transition->to_name == $form_moderation_state) {
workbench_email_create_form_element($form, $email_transition);
}
}
}
$form['actions']['submit']['#submit'][] = 'workbench_email_notification_submit';
}
}