You are here

public function WorkflowItem::settingsForm in Workflow 7

Same name and namespace in other branches
  1. 7.2 includes/Field/WorkflowItem.php \WorkflowItem::settingsForm()

File

includes/Field/WorkflowItem.php, line 60
Contains workflow\includes\Field\WorkflowItem.

Class

WorkflowItem
Plugin implementation of the 'workflow' field type.

Code

public function settingsForm(array $form, array &$form_state, $has_data) {
  $field_info = self::getInfo();
  $settings = $this->field['settings'];
  $settings += $field_info['workflow']['settings'];
  $settings['widget'] += $field_info['workflow']['settings']['widget'];
  $wid = $this->field['settings']['wid'];

  // Create list of all Workflow types. Include an initial empty value.
  // Validate each workflow, and generate a message if not complete.
  $workflows = array();
  $workflows[''] = t('- Select a value -');
  foreach (Workflow::getWorkflows() as $workflow) {
    if ($workflow
      ->validate()) {
      $workflows[$workflow->wid] = $workflow->name;
    }
  }
  if (count($workflows) == 1) {
    drupal_set_message(t('You must create at least one workflow before content can be assigned to a workflow.'));
  }

  // The allowed_values_functions is used in the formatter from list.module.
  $element['allowed_values_function'] = array(
    '#type' => 'value',
    '#value' => $settings['allowed_values_function'],
  );

  // Let the user choose between the available workflow types.
  $element['wid'] = array(
    '#type' => 'select',
    '#title' => t('Workflow type'),
    '#options' => $workflows,
    '#default_value' => $wid,
    '#required' => TRUE,
    '#disabled' => $has_data,
    '#description' => t('Choose the Workflow type.') . ' ' . t('Maintain workflows ') . l('here', 'admin/config/workflow/workflow') . '.',
  );

  // Inform the user of possible states.
  // If no Workflow type is selected yet, do not show anything.
  if ($wid) {

    // Get a string representation to show all options.
    $allowed_values_string = $this
      ->_allowed_values_string($wid);
    $element['allowed_values_string'] = array(
      '#type' => 'textarea',
      '#title' => t('Allowed values for the selected Workflow type'),
      '#default_value' => $allowed_values_string,
      '#rows' => 10,
      '#access' => TRUE,
      // user can see the data,
      '#disabled' => TRUE,
    );
  }
  $element['widget'] = array(
    '#type' => 'fieldset',
    '#title' => t('Workflow widget'),
    '#description' => 'Set some global properties of the widgets for this workflow. Some can be altered per widget instance.',
  );
  $element['widget']['options'] = array(
    '#type' => 'select',
    '#title' => t('How to show the available states'),
    '#required' => FALSE,
    '#default_value' => $settings['widget']['options'],
    //      '#multiple' => TRUE / FALSE,
    '#options' => array(
      // These options are taken from options.module
      'select' => 'Select list',
      'radios' => 'Radio buttons',
    ),
    '#description' => t('The Widget shows all available states. Decide which is the best way to show them.'),
  );
  $element['widget']['name_as_title'] = array(
    '#type' => 'checkbox',
    '#attributes' => array(
      'class' => array(
        'container-inline',
      ),
    ),
    '#title' => t('Use the workflow name as the title of the workflow form'),
    '#default_value' => $settings['widget']['name_as_title'],
    '#description' => t('The workflow section of the editing form is in its own fieldset. Checking the box will add the workflow ' . 'name as the title of workflow section of the editing form.'),
  );
  $element['widget']['schedule'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow scheduling of workflow transitions.'),
    '#required' => FALSE,
    '#default_value' => $settings['widget']['schedule'],
    '#description' => t('Workflow transitions may be scheduled to a moment in the future. ' . 'Soon after the desired moment, the transition is executed by Cron. ' . 'This may be hidden by settings in widgets, formatters or permissions.'),
  );
  $element['widget']['schedule_timezone'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show a timezone when scheduling a transition.'),
    '#required' => FALSE,
    '#default_value' => $settings['widget']['schedule_timezone'],
  );
  $element['widget']['comment'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow adding a comment to workflow transitions.'),
    '#required' => FALSE,
    '#default_value' => $settings['widget']['comment'],
    '#description' => t('On the Workflow form, a Comment form can be included so that the person making the state change can record ' . 'reasons for doing so. The comment is then included in the node\'s workflow history. ' . 'This may be hidden by settings in widgets, formatters or permissions.'),
  );
  $element['watchdog_log'] = array(
    '#type' => 'checkbox',
    '#attributes' => array(
      'class' => array(
        'container-inline',
      ),
    ),
    '#title' => t('Log informational watchdog messages when a transition is executed (a state value is changed)'),
    '#default_value' => $settings['watchdog_log'],
    '#description' => t('Optionally log transition state changes to watchdog.'),
  );
  $element['history'] = array(
    '#type' => 'fieldset',
    '#title' => t('Workflow history'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $element['history']['show'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use the workflow history, and show it on a separate tab.'),
    '#required' => FALSE,
    '#default_value' => $settings['history']['show'],
    '#description' => t('If checked, the state change is recorded in table {workflow_node_history}, ' . "and a tab 'Workflow' is shown on the node page, which gives access to the History of the workflow."),
  );
  $element['history']['roles'] = array(
    '#type' => 'checkboxes',
    '#options' => workflow_admin_ui_get_roles(),
    '#title' => t('Workflow history permissions'),
    '#default_value' => $settings['history']['roles'],
    '#description' => t('Select any roles that should have access to the workflow tab on nodes that have a workflow.'),
  );
  return $element;
}