function flag_actions_form in Flag 6.2
Same name and namespace in other branches
- 5 flag_actions.module \flag_actions_form()
- 6 flag_actions.module \flag_actions_form()
- 7.3 flag_actions.module \flag_actions_form()
- 7.2 flag_actions.module \flag_actions_form()
Generic configuration form for configuration of flag actions.
Parameters
$form_state: The form state.
$aid: If editing an action, an action ID must be passed in.
$flag_name: If adding a new action to a flag, a flag name must be specified.
1 string reference to 'flag_actions_form'
- flag_actions_menu in ./
flag_actions.module - Implements hook_menu().
File
- ./
flag_actions.module, line 365 - Actions support for the Flag module.
Code
function flag_actions_form($form_state, $aid = NULL, $flag_name = NULL) {
// This is a multistep form. Get the callback value if set and continue.
if (isset($form_state['storage']['callback'])) {
$callback = $form_state['storage']['callback'];
unset($form_state['storage']['callback']);
}
if (isset($aid)) {
$action = flag_actions_get_action($aid);
$callback = $action->callback;
$flag = flag_get_flag($action->flag);
drupal_set_title(t('Edit the "@action" action for the @title flag', array(
'@action' => $action->description,
'@title' => $flag
->get_title(),
)));
}
elseif (isset($flag_name)) {
$flag = flag_get_flag($flag_name);
}
if (empty($flag)) {
drupal_not_found();
}
$form = array();
$form['new'] = array(
'#type' => 'value',
'#value' => isset($callback) ? FALSE : TRUE,
);
if (!isset($callback)) {
drupal_set_title(t('Add an action to the @title flag', array(
'@title' => $flag
->get_title(),
)));
$actions = $flag
->get_valid_actions();
$options = array();
foreach ($actions as $key => $action) {
$options[$key] = $action['description'];
}
$form['callback'] = array(
'#title' => t('Select an action'),
'#type' => 'select',
'#options' => $options,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Continue'),
);
return $form;
}
elseif (!isset($action)) {
$actions = $flag
->get_valid_actions();
$action = (object) $actions[$callback];
$action->parameters = array();
$action->event = 'flag';
$action->threshold = 10;
$action->repeat_threshold = 0;
drupal_set_title(t('Add "@action" action to the @title flag', array(
'@action' => $action->description,
'@title' => $flag
->get_title(),
)));
}
$form['flag'] = array(
'#tree' => TRUE,
'#weight' => -9,
'#theme' => 'flag_actions_flag_form',
'#action' => $action,
'#flag' => $flag,
);
$form['flag']['flag'] = array(
'#type' => 'value',
'#value' => $flag,
);
$form['flag']['callback'] = array(
'#type' => 'value',
'#value' => $callback,
);
$form['flag']['aid'] = array(
'#type' => 'value',
'#value' => $aid,
);
$form['flag']['event'] = array(
'#type' => 'select',
'#options' => array(
'flag' => t('reaches'),
'unflag' => t('falls below'),
),
'#default_value' => $action->event,
);
$form['flag']['threshold'] = array(
'#type' => 'textfield',
'#size' => 6,
'#maxlength' => 6,
'#default_value' => $action->threshold,
'#required' => TRUE,
);
$form['flag']['repeat_threshold'] = array(
'#type' => 'textfield',
'#size' => 6,
'#maxlength' => 6,
'#default_value' => $action->repeat_threshold,
);
if ($flag->global) {
$form['flag']['threshold']['#disabled'] = 1;
$form['flag']['threshold']['#value'] = 1;
$form['flag']['repeat_threshold']['#access'] = FALSE;
$form['flag']['repeat_threshold']['#value'] = 0;
}
// Merge in the standard flag action form.
$action_form = $callback . '_form';
$edit = array();
if (function_exists($action_form)) {
$edit += $action->parameters;
$edit['actions_description'] = $action->description;
$edit['actions_type'] = $action->type;
$edit['actions_flag'] = $flag->name;
$additions = flag_actions_form_additions($action_form, $edit);
$form = array_merge($form, $additions);
}
// Add a few customizations to existing flag actions.
$flag_actions_form = 'flag_actions_' . $callback . '_form';
if (function_exists($flag_actions_form)) {
$flag_actions_form($form, $flag, $edit);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}