You are here

function ca_predicate_meta_form in Ubercart 6.2

Form to allow the creation and editing of conditional action predicates.

1 string reference to 'ca_predicate_meta_form'
ca_menu in ca/ca.module
Implements hook_menu().

File

ca/ca.admin.inc, line 136
Conditional actions overview UI.

Code

function ca_predicate_meta_form($form_state, $pid) {
  $predicate = array();

  // Load the predicate if an ID is passed in.
  if (!empty($pid) && $pid !== 0) {
    $predicate = ca_load_predicate($pid);

    // Fail out if we didn't find a predicate for that ID.
    if (empty($predicate)) {
      drupal_set_message(t('That predicate does not exist.'), 'error');
      drupal_goto(CA_UI_PATH);
    }
    drupal_set_title($predicate['#title']);
  }
  $form['predicate_pid'] = array(
    '#type' => 'value',
    '#value' => $pid,
  );
  $form['predicate_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#description' => t('Enter a title used for display on the overview tables.'),
    '#default_value' => $pid ? $predicate['#title'] : '',
    '#required' => TRUE,
  );

  // Create an array of triggers for the select box.
  $triggers = module_invoke_all('ca_trigger');
  foreach ($triggers as $key => $value) {
    $options[$value['#category']][$key] = $value['#title'];
  }
  $form['predicate_trigger'] = array(
    '#type' => 'select',
    '#title' => t('Trigger'),
    '#description' => t('Select the trigger for this predicate.<br />Cannot be modified if the predicate has conditions or actions.'),
    '#options' => $options,
    '#default_value' => $pid ? $predicate['#trigger'] : '',
    '#disabled' => empty($predicate['#conditions']) && empty($predicate['#actions']) ? FALSE : TRUE,
    '#required' => TRUE,
  );
  $form['predicate_description'] = array(
    '#type' => 'textarea',
    '#title' => t('Description'),
    '#description' => t('Enter a description that summarizes the use and intent of the predicate.'),
    '#default_value' => $pid ? isset($predicate['#description']) ? $predicate['#description'] : '' : '',
  );

  // Accommodate the mandatory custom prefix for predicate classes.
  $class = isset($predicate['#class']) ? $predicate['#class'] : '';
  if (strpos($class, 'custom') === 0) {
    $class = ltrim(substr($class, 6), ':');
  }
  if (is_numeric($pid)) {
    $form['predicate_class'] = array(
      '#type' => 'textfield',
      '#title' => t('Class'),
      '#description' => t('Classes let you categorize your predicates based on the type of functionality they provide.'),
      '#field_prefix' => 'custom:',
      '#default_value' => $class,
    );
  }
  else {
    $form['predicate_class'] = array(
      '#type' => 'value',
      '#value' => $class,
    );
  }
  $form['predicate_status'] = array(
    '#type' => 'radios',
    '#title' => t('Status'),
    '#description' => t('Disabled predicates will not be processed when their trigger is pulled.'),
    '#options' => array(
      1 => t('Enabled'),
      0 => t('Disabled'),
    ),
    '#default_value' => $pid ? $predicate['#status'] : 1,
  );
  $form['predicate_weight'] = array(
    '#type' => 'weight',
    '#title' => t('Weight'),
    '#description' => t('Predicates will be sorted by weight and processed sequentially.'),
    '#default_value' => $pid && isset($predicate['#weight']) ? $predicate['#weight'] : 0,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save predicate'),
    '#suffix' => l(t('Cancel'), CA_UI_PATH),
  );
  return $form;
}