function flag_actions_form in Flag 6
Same name and namespace in other branches
- 5 flag_actions.module \flag_actions_form()
- 6.2 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 - Implementation of hook_menu().
File
- ./
flag_actions.module, line 325 - 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;
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,
);
$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,
);
$action_form = $callback . '_form';
if (function_exists($action_form)) {
$edit = $action->parameters;
$edit['actions_description'] = $action->description;
$edit['actions_type'] = $action->type;
$form = array_merge($form, $action_form($edit));
}
$flag_actions_form = 'flag_actions_' . $callback . '_form';
if (function_exists($flag_actions_form)) {
$flag_actions_form($form, $flag, isset($edit) ? $edit : array());
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}