You are here

function trigger_assign_form in Drupal 6

Same name and namespace in other branches
  1. 7 modules/trigger/trigger.admin.inc \trigger_assign_form()

Create the form definition for assigning an action to a hook-op combination.

@ingoup forms

Parameters

$form_state: Information about the current form.

$hook: The name of the hook, e.g., 'nodeapi'.

$op: The name of the hook operation, e.g., 'insert'.

$description: A plain English description of what this hook operation does.

See also

trigger_assign_form_validate()

trigger_assign_form_submit()

1 string reference to 'trigger_assign_form'
trigger_forms in modules/trigger/trigger.module
Implementation of hook_forms(). We reuse code by using the same assignment form definition for each node-op combination.

File

modules/trigger/trigger.admin.inc, line 113
Admin page callbacks for the trigger module.

Code

function trigger_assign_form($form_state, $hook, $op, $description) {
  $form['hook'] = array(
    '#type' => 'hidden',
    '#value' => $hook,
  );
  $form['operation'] = array(
    '#type' => 'hidden',
    '#value' => $op,
  );

  // All of these forms use the same validate and submit functions.
  $form['#validate'][] = 'trigger_assign_form_validate';
  $form['#submit'][] = 'trigger_assign_form_submit';
  $options = array();
  $functions = array();

  // Restrict the options list to actions that declare support for this hook-op
  // combination.
  foreach (actions_list() as $func => $metadata) {
    if (isset($metadata['hooks']['any']) || isset($metadata['hooks'][$hook]) && is_array($metadata['hooks'][$hook]) && in_array($op, $metadata['hooks'][$hook])) {
      $functions[] = $func;
    }
  }
  foreach (actions_actions_map(actions_get_all_actions()) as $aid => $action) {
    if (in_array($action['callback'], $functions)) {
      $options[$action['type']][$aid] = $action['description'];
    }
  }
  $form[$op] = array(
    '#type' => 'fieldset',
    '#title' => t('Trigger: ') . $description,
    '#theme' => 'trigger_display',
  );

  // Retrieve actions that are already assigned to this hook-op combination.
  $actions = _trigger_get_hook_actions($hook, $op);
  $form[$op]['assigned']['#type'] = 'value';
  $form[$op]['assigned']['#value'] = array();
  foreach ($actions as $aid => $description) {
    $form[$op]['assigned']['#value'][$aid] = array(
      'description' => $description,
      'link' => l(t('unassign'), "admin/build/trigger/unassign/{$hook}/{$op}/" . md5($aid)),
    );
  }
  $form[$op]['parent'] = array(
    '#prefix' => "<div class='container-inline'>",
    '#suffix' => '</div>',
  );

  // List possible actions that may be assigned.
  if (count($options) != 0) {
    array_unshift($options, t('Choose an action'));
    $form[$op]['parent']['aid'] = array(
      '#type' => 'select',
      '#options' => $options,
    );
    $form[$op]['parent']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Assign'),
    );
  }
  else {
    $form[$op]['none'] = array(
      '#value' => t('No available actions for this trigger.'),
    );
  }
  return $form;
}