function workflow_notify_settings_form in Workflow 7
Same name and namespace in other branches
- 7.2 workflow_notify/workflow_notify.pages.inc \workflow_notify_settings_form()
Settings form.
2 string references to 'workflow_notify_settings_form'
- workflow_notify_menu in workflow_notify/
workflow_notify.module - Implements hook_menu().
- workflow_notify_og_form_alter in workflow_notify/
workflow_notify_og/ workflow_notify_og.module - Implements hook_form_alter(). Add a column for limiting user groups by OG group.
File
- workflow_notify/
workflow_notify.admin.inc, line 10 - Admin UI to Notify roles for Workfllow state transitions.
Code
function workflow_notify_settings_form($form, $form_state, $workflow) {
// If we don't have a workflow that goes with this, return to the admin pg.
if ($workflow) {
// Let's get a better page title.
drupal_set_title(t('@name Notifications', array(
'@name' => $workflow->name,
)));
// Let's add some breadcrumbs.
workflow_admin_ui_breadcrumbs($workflow);
$noyes = array(
t('No'),
t('Yes'),
);
$form['wid'] = array(
'#type' => 'value',
'#value' => $workflow->wid,
);
$form['#workflow'] = $workflow;
// Get all the states for this workflow, except the (creation) state.
$states = workflow_get_workflow_states_by_wid($workflow->wid, array(
'status' => 1,
'sysid' => 0,
));
if (!$states) {
$form['error'] = array(
'#type' => 'markup',
'#value' => t('There are no states defined for this workflow.'),
);
return $form;
}
$form['#states'] = $states;
// Get all roles, except anonymous.
$roles = user_roles(TRUE);
$roles = array(
'-1' => t('Author'),
) + user_roles(TRUE);
// The module_invoke_all function does not allow passing by reference.
$args = array(
'roles' => $roles,
);
foreach (module_implements('workflow_notify') as $module) {
$function = $module . '_workflow_notify';
// Call the $op='roles' hooks so the list may be modified.
$function('roles', $args);
}
// Get the modified list.
$roles = $args['roles'];
// Setting for "from" address.
$form['from_address'] = array(
'#title' => t('Set "From" address to'),
'#type' => 'radios',
'#options' => array(
'site' => t('Site email address'),
'changer' => t('Current user'),
),
'#default_value' => variable_get('workflow_notify_from_address_' . $workflow->wid, 'site'),
'#attributes' => array(
'class' => array(
'container-inline',
),
),
'#description' => t('Determines whether to use the site address or the address of the person
causing the state change.'),
);
// Get the list of input formats.
$formats = array();
foreach (filter_formats() as $fid => $filter) {
$formats[$fid] = $filter->name;
}
$form['filter'] = array(
'#title' => t('Filter format to use on message'),
'#type' => 'radios',
'#options' => $formats,
'#default_value' => variable_get('workflow_notify_filter_format_' . $workflow->wid, 'filtered_html'),
'#attributes' => array(
'class' => array(
'container-inline',
),
),
'#description' => t('The message body will be processed using this filter format
in order to ensure security.'),
);
$form['tokens'] = array(
'#theme' => 'token_tree_link',
'#token_types' => array(
'node',
'workflow',
),
);
// Column names for theme function.
$columns = array(
'state' => t('State'),
'roles' => t('Roles to notify'),
);
$args = array(
'columns' => $columns,
);
// The module_invoke_all function does not allow passing by reference.
foreach (module_implements('workflow_notify') as $module) {
$function = $module . '_workflow_notify';
$function('columns', $args);
}
$form['#columns'] = $args['columns'];
// We always want subject and body last.
$form['#columns']['subject'] = t('Subject');
$form['#columns']['body'] = t('Body');
$notify = variable_get('workflow_notify_roles', array());
foreach ($states as $sid => $state) {
// Allow modules to insert state operations.
$state_links = module_invoke_all('workflow_operations', 'state', $workflow, $state);
$form['states'][$sid] = array(
'state' => array(
'#type' => 'markup',
'#markup' => filter_xss($state->state),
),
'roles' => array(
'#type' => 'checkboxes',
'#options' => $roles,
'#default_value' => isset($notify[$sid]) ? $notify[$sid] : array(),
'#attributes' => array(
'class' => array(
'state-roles',
),
),
),
'subject' => array(
'#type' => 'textarea',
'#rows' => 5,
'#default_value' => variable_get('workflow_notify_subject_' . $sid, '[node:title] is now "[workflow:workflow-current-state-name]"'),
'#attributes' => array(
'class' => array(
'subject',
),
),
),
'body' => array(
'#type' => 'textarea',
'#rows' => 5,
'#default_value' => variable_get('workflow_notify_body_' . $sid, '<a href="[node:url:absolute]">[node:title]</a> is now "[workflow:workflow-current-state-name]".'),
'#attributes' => array(
'class' => array(
'body',
),
),
),
);
}
$form['#tree'] = TRUE;
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Save notifications settings',
);
return $form;
}
else {
drupal_goto('admin/config/workflow/workflow');
}
}