function action_admin_configure

Form constructor for the configuration of a single action.

We provide the "Description" field. The rest of the form is provided by the action. We then provide the Save button. Because we are combining unknown form elements with the action configuration form, we use an 'action_' prefix on our elements.

Parameters

$action: Hash of an action ID or an integer. If it is a hash, we are creating a new instance. If it is an integer, we are editing an existing instance.

See also

action_admin_configure_validate()

action_admin_configure_submit()

Related topics

1 string reference to 'action_admin_configure'
action_menu in drupal/core/modules/action/action.module
Implements hook_menu().

File

drupal/core/modules/action/action.admin.inc, line 144
Admin page callbacks for the Action module.

Code

function action_admin_configure($form, &$form_state, $action = NULL) {
  if ($action === NULL) {
    drupal_goto('admin/config/system/actions');
  }
  $actions_map = action_actions_map(action_list());
  $edit = array();

  // Numeric action denotes saved instance of a configurable action.
  if (is_numeric($action)) {
    $aid = $action;

    // Load stored parameter values from database.
    $data = db_query("SELECT * FROM {actions} WHERE aid = :aid", array(
      ':aid' => $aid,
    ))
      ->fetch();
    $edit['action_label'] = $data->label;
    $edit['action_type'] = $data->type;
    $function = $data->callback;
    $action = drupal_hash_base64($data->callback);
    $params = unserialize($data->parameters);
    if ($params) {
      foreach ($params as $name => $val) {
        $edit[$name] = $val;
      }
    }
  }
  else {
    $function = $actions_map[$action]['callback'];
    $edit['action_label'] = $actions_map[$action]['label'];
    $edit['action_type'] = $actions_map[$action]['type'];
  }
  $form['action_label'] = array(
    '#type' => 'textfield',
    '#title' => t('Label'),
    '#default_value' => $edit['action_label'],
    '#maxlength' => '255',
    '#description' => t('A unique label for this advanced action. This label will be displayed in the interface of modules that integrate with actions.'),
    '#weight' => -10,
  );
  $action_form = $function . '_form';
  $form = array_merge($form, $action_form($edit));
  $form['action_type'] = array(
    '#type' => 'value',
    '#value' => $edit['action_type'],
  );
  $form['action_action'] = array(
    '#type' => 'hidden',
    '#value' => $action,
  );

  // $aid is set when configuring an existing action instance.
  if (isset($aid)) {
    $form['action_aid'] = array(
      '#type' => 'hidden',
      '#value' => $aid,
    );
  }
  $form['action_configured'] = array(
    '#type' => 'hidden',
    '#value' => '1',
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#weight' => 13,
  );
  return $form;
}