You are here

function _activity_settings_form_messages in Activity 6.2

Show the text boxes according to the _triggers and _ops steps.

1 call to _activity_settings_form_messages()
activity_form in ./activity.admin.inc
Menu callback to administer activity messages.
1 string reference to '_activity_settings_form_messages'
_activity_settings_form_operations in ./activity.admin.inc
List the ops for the module selected in the _triggers step.

File

./activity.admin.inc, line 324
activity.admin.inc Contains administrative forms for activity.module

Code

function _activity_settings_form_messages(&$form_state) {
  $form = array();
  if (isset($form_state['storage']['step'])) {
    $hook = $form_state['storage']['values']['triggers']['hook'];
    $module = activity_module_name($hook);
    $operation = $form_state['storage']['values']['operations']['operation'];
    $aid = FALSE;
    $activity_types = isset($form_state['storage']['values']['operations']['activity_types']) ? $form_state['storage']['values']['operations']['activity_types'] : array();
  }
  else {
    $aid = $form_state['storage']['action']->aid;

    // by doing this we assume that an action is not assigned to more than one trigger
    $result = db_query('SELECT hook, op FROM {trigger_assignments} WHERE aid = %d', $aid);
    while ($row = db_fetch_array($result)) {
      $hook = $form_state['storage']['values']['triggers']['hook'] = $row['hook'];
      $module = activity_module_name($hook);
      $operation = $form_state['storage']['values']['operations']['operation'] = $row['op'];
    }
  }
  $module_info = activity_get_module_info($module);
  if (isset($form_state['storage']['action'])) {
    $default_values = unserialize($form_state['storage']['action']->parameters);
  }
  else {
    $default_values = array();
  }

  // If this came through the multistep process it is already set above.
  // Otherwise we need to get it from the default values
  if (!isset($activity_types)) {
    if (isset($default_values['activity_types'])) {
      $activity_types = $default_values['activity_types'];
    }
    else {
      $activity_types = array();
    }
  }
  $form_state['storage']['values']['operations']['activity_types'] = $activity_types;

  // Filter out false checkboxes.
  $activity_types = array_filter($activity_types);
  if (empty($activity_types)) {
    $types = 'All';
  }
  else {
    $types = implode(', ', array_intersect_key($module_info->type_options, $activity_types));
  }
  $form['description'] = array(
    '#type' => 'textfield',
    '#title' => t('Description'),
    '#default_value' => isset($form_state['storage']['action']) ? $form_state['storage']['action']->description : t('Record an activity message when: !module !op types !types', array(
      '!module' => $module,
      '!op' => $operation,
      '!types' => $types,
    )),
    '#maxlength' => '254',
    '#description' => t('A unique description for this advanced action. This description will be displayed in the interface of modules that integrate with actions, such as Trigger module.'),
  );

  // @todo: extend ->objects to have a description which will fill out the
  //  #description for this form element. Remember to adjust logic everywhere
  //  ->objects is used.
  foreach (activity_enabled_languages() as $id => $language) {
    $form["{$id}_fieldset"] = array(
      '#type' => 'fieldset',
      '#title' => t('@name messages', array(
        '@name' => $language->name,
      )),
      '#collapsible' => TRUE,
      '#collapsed' => $id != language_default('language'),
    );
    foreach ($module_info->objects as $label => $type) {
      $clean_type = drupal_ucfirst(str_replace('_', ' ', $label));
      $form["{$id}_fieldset"][$type . '-pattern-' . $id] = array(
        '#type' => 'textarea',
        '#title' => t('!type message', array(
          '!type' => $clean_type,
        )),
        '#default_value' => isset($default_values[$type . '-pattern-' . $id]) ? $default_values[$type . '-pattern-' . $id] : '',
        '#description' => t('Using the available tokens, enter a message as how it should <strong>appear to the !type</strong> of this particular activity.', array(
          '!type' => $clean_type,
        )),
      );
    }
    $form["{$id}_fieldset"]['everyone-pattern-' . $id] = array(
      '#type' => 'textarea',
      '#title' => t('Public message'),
      '#default_value' => isset($default_values['everyone-pattern-' . $id]) ? $default_values['everyone-pattern-' . $id] : '',
      '#description' => t('Using the available tokens, enter a message as how it should <strong>appear to anyone who is <em>not</em> the author</strong> of this particular activity.'),
    );
  }

  // don't show the back button when editing
  if (!isset($form_state['storage']['action'])) {
    $form['back'] = array(
      '#type' => 'submit',
      '#value' => 'Back',
    );
  }
  $form['save'] = array(
    '#type' => 'submit',
    '#value' => 'Save',
  );
  $form['step_prev'] = array(
    '#type' => 'value',
    '#value' => '_activity_settings_form_operations',
  );
  $form['this_step'] = array(
    '#type' => 'value',
    '#value' => 'messages',
  );
  $form['token_help'] = array(
    '#type' => 'fieldset',
    '#title' => t('Available tokens'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['token_help']['tokens'] = array(
    '#type' => 'markup',
    '#value' => theme('activity_token_help', array_values($module_info->objects)),
  );
  $form['aid'] = array(
    '#type' => 'value',
    '#value' => $aid,
  );
  return $form;
}