You are here

function workflow_notify_settings_form in Workflow 7.2

Same name and namespace in other branches
  1. 7 workflow_notify/workflow_notify.admin.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().

File

workflow_notify/workflow_notify.pages.inc, line 11
Admin UI to Notify roles for Workflow state transitions.

Code

function workflow_notify_settings_form($form, &$form_state, Workflow $workflow) {

  // If we don't have a workflow that goes with this, return to the admin pg.
  if (!is_object($workflow)) {
    drupal_set_message(t('Improper worklow ID provided.'), 'error');
    drupal_goto(WORKFLOW_ADMIN_UI_PATH);
  }

  // @todo: Let's get a better page title.
  drupal_set_title(t('@name Notifications', array(
    '@name' => $workflow
      ->label(),
  )));

  // Let's add some breadcrumbs.
  // workflow_admin_ui_breadcrumbs($workflow);
  $form['#tree'] = TRUE;
  $form['#wid'] = $wid = $workflow
    ->getWorkflowId();
  $form['#workflow'] = $workflow;
  $noyes = array(
    t('No'),
    t('Yes'),
  );

  // Get all the states for this workflow, except the (creation) state.
  $states = $workflow
    ->getStates();
  $form['#states'] = $states;
  if (!$states) {
    $form['#columns'] = array();
    $form['error'] = array(
      '#type' => 'markup',
      '#value' => t('There are no states defined for this workflow.'),
    );
    return $form;
  }

  // A list of role names keyed by role ID, including the 'author' role.
  $roles = workflow_get_roles('participate in workflow');

  // 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_{$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_{$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 "[node:field_workflow_state:new-state:label]"'),
        '#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 "[node:field_workflow_state:new-state:label]".'),
        '#attributes' => array(
          'class' => array(
            'body',
          ),
        ),
      ),
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  return $form;
}