function flag_form_submit in Flag 7.3
Same name and namespace in other branches
- 8.4 flag.module \flag_form_submit()
- 5 includes/flag.admin.inc \flag_form_submit()
- 6.2 includes/flag.admin.inc \flag_form_submit()
- 6 includes/flag.admin.inc \flag_form_submit()
- 7.2 includes/flag.admin.inc \flag_form_submit()
Add/Edit flag form submit.
File
- includes/
flag.admin.inc, line 684 - Contains administrative pages for creating, editing, and deleting flags.
Code
function flag_form_submit($form, &$form_state) {
$flag = $form['#flag'];
$form_state['values']['title'] = trim($form_state['values']['title']);
$flag
->form_input($form_state['values']);
$flag
->save();
$flag
->enable();
drupal_set_message(t('Flag @title has been saved.', array(
'@title' => $flag
->get_title(),
)));
// We clear caches more vigorously if the flag was new.
_flag_clear_cache($flag->entity_type, !empty($flag->is_new));
if (!empty($flag->is_new)) {
field_attach_create_bundle('flagging', $flag->name);
}
// Save permissions.
// This needs to be done after the flag cache has been cleared, so that
// the new permissions are picked up by hook_permission().
// This may need to move to the flag class when we implement extra permissions
// for different flag types: http://drupal.org/node/879988
// If the flag machine name as changed, clean up all the obsolete permissions
// and notify FieldAPI.
if ($flag->name != $form['#flag_name']) {
$old_name = $form['#flag_name'];
$permissions = array(
"flag {$old_name}",
"unflag {$old_name}",
);
foreach (array_keys(user_roles()) as $rid) {
user_role_revoke_permissions($rid, $permissions);
}
field_attach_rename_bundle('flagging', $old_name, $flag->name);
}
foreach (array_keys(user_roles(!module_exists('session_api'))) as $rid) {
// Create an array of permissions, based on the checkboxes element name.
$permissions = array(
"flag {$flag->name}" => $flag->roles['flag'][$rid],
"unflag {$flag->name}" => $flag->roles['unflag'][$rid],
);
user_role_change_permissions($rid, $permissions);
}
// @todo: when we add database caching for flags we'll have to clear the
// cache again here.
$form_state['redirect'] = FLAG_ADMIN_PATH;
}