class flag_user in Flag 7.2
Same name and namespace in other branches
- 5 flag.inc \flag_user
- 6.2 flag.inc \flag_user
- 6 flag.inc \flag_user
- 7.3 includes/flag/flag_user.inc \flag_user
Implements a user flag.
Hierarchy
- class \flag_entity extends \flag_flag
- class \flag_user
Expanded class hierarchy of flag_user
1 string reference to 'flag_user'
- flag_flag_definitions in ./
flag.inc - Implements hook_flag_definitions().
File
- ./
flag.inc, line 1751 - Implements various flags. Uses object oriented style inspired by that of Views 2.
View source
class flag_user extends flag_entity {
function options() {
$options = parent::options();
// We supersede, but do not supplant, the regular entity display with an
// option that's formatted in the style of user profiles.
$options['show_on_entity'] = FALSE;
$options += array(
'show_on_profile' => TRUE,
'access_uid' => '',
);
return $options;
}
/**
* Options form extras for user flags.
*/
function options_form(&$form) {
parent::options_form($form);
$form['access']['types'] = array(
// A user flag doesn't support node types.
// TODO: Maybe support roles instead of node types.
'#type' => 'value',
'#value' => array(
0 => 0,
),
);
$form['access']['access_uid'] = array(
'#type' => 'checkbox',
'#title' => t('Users may flag themselves'),
'#description' => t('Disabling this option may be useful when setting up a "friend" flag, when a user flagging themself does not make sense.'),
'#default_value' => $this->access_uid ? 0 : 1,
);
$form['display']['show_on_profile'] = array(
'#type' => 'checkbox',
'#title' => t('Display link on user profile page'),
'#description' => t('Show the link formatted as a user profile element.'),
'#default_value' => $this->show_on_profile,
'#access' => empty($this->locked['show_on_profile']),
// Put this above 'show on entity'.
'#weight' => -1,
);
// Explain how 'show on entity' is different.
$form['display']['show_on_entity']['#description'] = t('Show the link in the same format as on other entities.');
}
function form_input($form_values) {
parent::form_input($form_values);
// The access_uid value is intentionally backwards from the UI, to avoid
// confusion caused by checking a box to disable a feature.
$this->access_uid = empty($form_values['access_uid']) ? 'others' : '';
}
function type_access($content_id, $action, $account) {
// Prevent users from flagging themselves.
if ($this->access_uid == 'others' && $content_id == $account->uid) {
return FALSE;
}
}
function type_access_multiple($content_ids, $account) {
$access = array();
// Exclude anonymous.
if (array_key_exists(0, $content_ids)) {
$access[0] = FALSE;
}
// Prevent users from flagging themselves.
if ($this->access_uid == 'others' && array_key_exists($account->uid, $content_ids)) {
$access[$account->uid] = FALSE;
}
return $access;
}
function get_flag_action($content_id) {
$flag_action = parent::get_flag_action($content_id);
$user = $this
->fetch_content($content_id);
$flag_action->content_title = $user->name;
$flag_action->content_url = _flag_url('user/' . $user->uid);
return $flag_action;
}
function get_relevant_action_objects($content_id) {
return array(
'user' => $this
->fetch_content($content_id),
);
}
function get_views_info() {
$views_info = parent::get_views_info();
$views_info['title field'] = 'name';
return $views_info;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
flag_entity:: |
function | Checks whether the flag applies for the current entity bundle. | ||
flag_entity:: |
function | Returns the entity id, if it already exists. | 1 | |
flag_entity:: |
function | Returns token types for the current entity type. | 1 | |
flag_entity:: |
function | Replaces tokens. | 2 | |
flag_entity:: |
function | Returns TRUE if the link should be displayed. | 2 | |
flag_entity:: |
function | Loads the entity object. | ||
flag_user:: |
function | |||
flag_user:: |
function |
Returns a 'flag action' object. Overrides flag_entity:: |
||
flag_user:: |
function |
Returns objects the action may possible need. Overrides flag_entity:: |
||
flag_user:: |
function |
Returns information for the Views integration. Overrides flag_entity:: |
||
flag_user:: |
function |
Adds additional options that are common for all entity types. Overrides flag_entity:: |
||
flag_user:: |
function |
Options form extras for user flags. Overrides flag_entity:: |
||
flag_user:: |
function | |||
flag_user:: |
function |