flag_action_form

  1. drupal
    1. 6 flag.actions.inc function
    2. 7 flag.actions.inc function
Drupal 7 flag_action_form($context, $content_type)

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()

File

sites/all/modules/flag/includes/flag.actions.inc, line 185
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 = drupal_map_assoc(array_keys($flags));

  $form['flag_action']['#tree'] = TRUE;
  $form['flag_action']['warning'] = array(
    '#markup' => '<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(FLAG_ADMIN_PATH . '/add')));
    $form['flag_action']['flag']['#type'] = 'item';
    $form['flag_action']['flag']['#markup'] = $error;
    $form['flag_action']['flag']['#element_validate'][] = 'flag_action_validate_flag';
    $form['flag_action']['flag']['#flag_error'] = $error;
  }

  return $form;
}