You are here

function flag_action_form in Flag 6.2

Same name and namespace in other branches
  1. 7.3 includes/flag.actions.inc \flag_action_form()
  2. 7.2 includes/flag.actions.inc \flag_action_form()

Generic form for configuring Flag actions.

Parameters

$context: The current action context.

$content_type: The content type applicable to this action, such as "node" or "comment".

3 calls to flag_action_form()
flag_comment_action_form in includes/flag.actions.inc
Form for configuring the Flag comment action.
flag_node_action_form in includes/flag.actions.inc
Form for configuring the Flag node action.
flag_user_action_form in includes/flag.actions.inc
Form for configuring the Flag user action.

File

includes/flag.actions.inc, line 184
Hooks for flag actions.

Code

function flag_action_form($context, $content_type) {
  $form = array();
  $flags = flag_get_flags($content_type);

  // If this is a flag_action action, do not allow the triggering flag.
  if (isset($context['actions_flag'])) {
    unset($flags[$context['actions_flag']]);
  }
  $options = array();
  foreach ($flags as $key => $flag) {
    $options[$key] = $flag->title;
  }
  $form['flag_action']['#tree'] = TRUE;
  $form['flag_action']['warning'] = array(
    '#value' => '<div class="messages status">' . t("Note when setting a flag through actions, the selected flag will be flagged regardless of the user's permissions.") . '</div>',
  );
  $form['flag_action']['flag'] = array(
    '#title' => t('Flag to affect'),
    '#type' => 'radios',
    '#options' => $options,
    '#required' => TRUE,
    '#description' => t('When this action is fired, which flag should be flagged (or unflagged)?'),
    '#default_value' => isset($context['flag_action']['flag']) ? $context['flag_action']['flag'] : reset($options),
  );
  $form['flag_action']['op'] = array(
    '#title' => t('Flag operation'),
    '#type' => 'radios',
    '#options' => array(
      'flag' => t('Flag'),
      'unflag' => t('Unflag'),
    ),
    '#description' => t('When this action is fired, which operation should be performed on the flag?'),
    '#default_value' => isset($context['flag_action']['op']) ? $context['flag_action']['op'] : 'flag',
  );
  if (empty($options)) {
    $error = t('There are no available %type flags. Before you can create an action of this type, you need to <a href="!url">create a %type flag</a>.', array(
      '%type' => $content_type,
      '!url' => url('admin/build/flags/add'),
    ));
    $form['flag_action']['flag']['#type'] = 'item';
    $form['flag_action']['flag']['#children'] = $error;
    $form['flag_action']['flag']['#element_validate'][] = 'flag_action_validate_flag';
    $form['flag_action']['flag']['#flag_error'] = $error;
  }
  return $form;
}