function flag_confirm in Flag 7.3
Same name and namespace in other branches
- 5 flag.module \flag_confirm()
- 6.2 flag.module \flag_confirm()
- 6 flag.module \flag_confirm()
- 7.2 flag.module \flag_confirm()
Form for confirming the (un)flagging of an entity.
Parameters
string $action: Either 'flag' or 'unflag'.
flag_flag $flag: A loaded flag object.
int $entity_id: The id of the entity to operate on. The type is implicit in the flag.
See also
1 string reference to 'flag_confirm'
- flag_menu in ./
flag.module - Implements hook_menu().
File
- includes/
flag.pages.inc, line 87 - Menu callbacks for the Flag module.
Code
function flag_confirm($form, &$form_state, $action, $flag, $entity_id) {
$form['#flag'] = $flag;
$form['action'] = array(
'#type' => 'value',
'#value' => $action,
);
$form['entity_id'] = array(
'#type' => 'value',
'#value' => $entity_id,
);
$question = $flag
->get_label($action . '_confirmation', $entity_id);
$path = isset($_GET['destination']) ? $_GET['destination'] : '<front>';
$yes = strip_tags($flag
->get_label($action . '_short', $entity_id));
if ($action == 'flag') {
// If the action 'flag', we're potentially about to create a new
// flagging entity. We need an empty new entity to pass to FieldAPI.
$flagging = $flag
->new_flagging($entity_id);
field_attach_form('flagging', $flagging, $form, $form_state);
$form['#flagging'] = $flagging;
// Take the same approach as Core entity forms: shove all the entity
// properties into the form as values so that entity_form_field_validate()
// can build a pseudoentity from $form_values in the validate handler.
foreach (array(
'flag_name',
'entity_type',
'entity_id',
'uid',
) as $key) {
$form[$key] = array(
'#type' => 'value',
'#value' => isset($flagging->{$key}) ? $flagging->{$key} : NULL,
);
}
}
return confirm_form($form, $question, $path, '', $yes);
}