function flag_form in Flag 6
Same name and namespace in other branches
- 5 includes/flag.admin.inc \flag_form()
- 6.2 includes/flag.admin.inc \flag_form()
- 7.3 includes/flag.admin.inc \flag_form()
- 7.2 includes/flag.admin.inc \flag_form()
Add/Edit flag page.
2 string references to 'flag_form'
- flag_add_page in includes/
flag.admin.inc - Menu callback for adding a new flag.
- flag_menu in ./
flag.module - Implementation of hook_menu().
File
- includes/
flag.admin.inc, line 165 - Contains administrative pages for creating, editing, and deleting flags.
Code
function flag_form(&$form_state, $name, $type = NULL) {
if (isset($type)) {
// Adding a new flag.
$flag = flag_flag::factory_by_content_type($type);
$flag->name = $name;
drupal_set_title(t('Add new flag'));
}
else {
// Editing an existing flag.
$flag = flag_get_flag($name);
if (empty($flag)) {
// Check if we're overriding a default flag.
$default_flags = flag_get_default_flags(TRUE);
if (isset($default_flags[$name])) {
$flag = $default_flags[$name];
}
else {
drupal_goto('admin/build/flags');
}
}
drupal_set_title(t('Edit @title flag', array(
'@title' => $flag
->get_title(),
)));
}
$form['#flag'] = $flag;
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#default_value' => $flag->name,
'#description' => t('The machine-name for this flag. It may be up to 32 characters long and my only contain lowercase letters, underscores, and numbers. It will be used in URLs and in all API calls.'),
'#maxlength' => 32,
'#required' => TRUE,
'#access' => empty($flag->locked['name']),
);
if (!empty($flag->fid)) {
$form['name']['#description'] .= ' <strong>' . t('Change this value only with great care.') . '</strong>';
}
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => $flag->title,
'#description' => t('A short, descriptive title for this flag. It will be used in administrative interfaces to refer to this flag, and in page titles and menu items of some <a href="@insite-views-url">views</a> this module provides (theses are customizable, though). Some examples could be <em>Bookmarks</em>, <em>Favorites</em>, or <em>Offensive</em>.', array(
'@insite-views-url' => url('admin/build/views'),
)),
'#maxlength' => 255,
'#required' => TRUE,
'#access' => empty($flag->locked['title']),
);
$form['flag_short'] = array(
'#type' => 'textfield',
'#title' => t('Flag link text'),
'#default_value' => $flag->flag_short,
'#description' => t('The text for the "flag this" link for this flag.'),
'#required' => TRUE,
'#access' => empty($flag->locked['flag_short']),
);
$form['flag_long'] = array(
'#type' => 'textfield',
'#title' => t('Flag link description'),
'#default_value' => $flag->flag_long,
'#description' => t('The description of the "flag this" link. Usually displayed on mouseover.'),
'#access' => empty($flag->locked['flag_long']),
);
$form['flag_confirmation'] = array(
'#type' => 'textfield',
'#title' => t('Flag confirmation message'),
'#default_value' => $flag->flag_confirmation,
'#description' => t('Message displayed if the user has clicked the "flag this" link and confirmation is required. Usually presented in the form of a question such as, "Are you sure you want to flag this content?"'),
'#access' => empty($flag->locked['flag_confirmation']),
);
$form['flag_message'] = array(
'#type' => 'textfield',
'#title' => t('Flagged message'),
'#default_value' => $flag->flag_message,
'#description' => t('Message displayed after flagging content. If JavaScript is enabled, it will be displayed below the link. If not, it will be displayed in the message area.'),
'#access' => empty($flag->locked['flag_message']),
);
$form['unflag_short'] = array(
'#type' => 'textfield',
'#title' => t('Unflag link text'),
'#default_value' => $flag->unflag_short,
'#description' => t('The text for the "unflag this" link for this flag.'),
'#required' => TRUE,
'#access' => empty($flag->locked['unflag_short']),
);
$form['unflag_long'] = array(
'#type' => 'textfield',
'#title' => t('Unflag link description'),
'#default_value' => $flag->unflag_long,
'#description' => t('The description of the "unflag this" link. Usually displayed on mouseover.'),
'#access' => empty($flag->locked['unflag_long']),
);
$form['unflag_confirmation'] = array(
'#type' => 'textfield',
'#title' => t('Unflag confirmation message'),
'#default_value' => $flag->unflag_confirmation,
'#description' => t('Message displayed if the user has clicked the "unflag this" link and confirmation is required. Usually presented in the form of a question such as, "Are you sure you want to unflag this content?"'),
'#access' => empty($flag->locked['unflag_confirmation']),
);
$form['unflag_message'] = array(
'#type' => 'textfield',
'#title' => t('Unflagged message'),
'#default_value' => $flag->unflag_message,
'#description' => t('Message displayed after content has been unflagged. If JavaScript is enabled, it will be displayed below the link. If not, it will be displayed in the message area.'),
'#access' => empty($flag->locked['unflag_message']),
);
if (module_exists('token')) {
$form['token_help'] = array(
'#title' => t('Token replacement'),
'#type' => 'fieldset',
'#description' => t('The above six options may contain the following wildcard replacements. For example, "Mark Link" could be entered as "Add [title] to your flags" or "Add this [type-name] to your flags". These wildcards will be replaced with the appropriate field from the node.') . theme('flag_token_help', $flag
->get_labels_token_types()),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
}
else {
$form['token_help'] = array(
'#value' => '<em>' . t('Note: You don\'t have the <a href="@token-url">Token</a> module installed. If you have it installed, and enabled, you\'ll be able to embed tokens in the six labels above.', array(
'@token-url' => 'http://drupal.org/project/token',
)) . '</em>',
);
}
$form['global'] = array(
'#type' => 'checkbox',
'#title' => t('Global flag'),
'#default_value' => $flag->global,
'#description' => t('If checked, flag is considered "global" and each node is either flagged or not. If unchecked, each user has individual flags on content.'),
'#weight' => 1,
'#access' => empty($flag->locked['global']),
);
$form['roles'] = array(
'#type' => 'checkboxes',
'#title' => t('Roles that may use this flag'),
'#options' => user_roles(TRUE),
'#default_value' => $flag->roles,
'#description' => t('Checking <em>authenticated user</em> will allow all logged-in users to flag content with this flag. Anonymous users may not flag content.'),
'#weight' => 5,
'#access' => empty($flag->locked['roles']),
);
// Disabled access breaks checkboxes unless #value is hard coded.
if (!empty($flag->locked['roles'])) {
$form['roles']['#value'] = $flag->roles;
}
$form['types'] = array(
'#type' => 'checkboxes',
'#title' => t('What nodes this flag may be used on'),
'#options' => array_map('check_plain', node_get_types('names')),
'#default_value' => $flag->types,
'#description' => t('Check any node types that this flag may be used on. You must check at least one node type.'),
'#required' => TRUE,
'#weight' => 10,
'#access' => empty($flag->locked['types']),
);
// Disabled access breaks checkboxes unless #value is hard coded.
if (!empty($flag->locked['types'])) {
$form['types']['#value'] = $flag->types;
}
$form['display'] = array(
'#type' => 'fieldset',
'#title' => t('Display options'),
'#description' => t('Flags are usually controlled through links that allow users to toggle their behavior. You can choose how users interact with flags by changing options here. It is legitimate to have none of the following checkboxes ticked, if, for some reason, you wish <a href="@placement-url">to place the the links on the page yourself</a>.', array(
'@placement-url' => 'http://drupal.org/node/295383',
)),
'#tree' => FALSE,
'#weight' => 20,
);
$form['display']['link_type'] = array(
'#type' => 'radios',
'#title' => t('Link type'),
'#options' => _flag_link_type_options(),
'#default_value' => $flag->link_type,
'#weight' => 2,
'#access' => empty($flag->locked['link_type']),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
// We put this button on the form before calling $flag->options_form()
// to give the flag handler a chance to remove it (e.g. flag_broken).
'#weight' => 999,
);
$flag
->options_form($form);
return $form;
}