class flag_user in Flag 7.3
Same name and namespace in other branches
- 5 flag.inc \flag_user
- 6.2 flag.inc \flag_user
- 6 flag.inc \flag_user
- 7.2 flag.inc \flag_user
Implements a user flag.
Hierarchy
- class \flag_flag
- class \flag_entity
- class \flag_user
- class \flag_entity
Expanded class hierarchy of flag_user
1 string reference to 'flag_user'
- flag_flag_type_info in ./
flag.flag.inc - Implements hook_flag_type_info().
File
- includes/
flag/ flag_user.inc, line 11 - Contains the flag_user class.
View source
class flag_user extends flag_entity {
function options() {
$options = parent::options();
$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,
// Put this above 'show on entity'.
'#weight' => -1,
);
}
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($entity_id, $action, $account) {
// Prevent users from flagging themselves.
if ($this->access_uid == 'others' && $entity_id == $account->uid) {
return FALSE;
}
}
function type_access_multiple($entity_ids, $account) {
$access = array();
// Exclude anonymous.
if (array_key_exists(0, $entity_ids)) {
$access[0] = FALSE;
}
// Prevent users from flagging themselves.
if ($this->access_uid == 'others' && array_key_exists($account->uid, $entity_ids)) {
$access[$account->uid] = FALSE;
}
return $access;
}
function get_flag_action($entity_id) {
$flag_action = parent::get_flag_action($entity_id);
$user = $this
->fetch_entity($entity_id);
$flag_action->content_title = $user->name;
$flag_action->content_url = $this
->_flag_url('user/' . $user->uid);
return $flag_action;
}
function get_relevant_action_objects($entity_id) {
return array(
'user' => $this
->fetch_entity($entity_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. Overrides flag_flag:: |
||
flag_entity:: |
function |
Returns the entity id, if it already exists. Overrides flag_flag:: |
1 | |
flag_entity:: |
function |
Returns token types for the current entity type. Overrides flag_flag:: |
1 | |
flag_entity:: |
function |
Provides permissions for this flag. Overrides flag_flag:: |
||
flag_entity:: |
protected | function |
Invoke a Rules event in reaction to a flagging or unflagging. Overrides flag_flag:: |
|
flag_entity:: |
function |
Replaces tokens. Overrides flag_flag:: |
2 | |
flag_entity:: |
function |
Determine whether the flag should show a flag link in entity links. Overrides flag_flag:: |
||
flag_entity:: |
function |
Loads the entity object. Overrides flag_flag:: |
||
flag_flag:: |
property | The entity type this flag works with. | ||
flag_flag:: |
public | property | An associative array containing textual errors that may be created during validation. | |
flag_flag:: |
property | The database ID. | ||
flag_flag:: |
property | Whether this flag state should act as a single toggle to all users. | ||
flag_flag:: |
property | The flag's "machine readable" name. | ||
flag_flag:: |
property | The roles array. This can be populated by fetch_roles() when needed. | ||
flag_flag:: |
property | The human-readable title for this flag. | ||
flag_flag:: |
property | The sub-types, AKA bundles, this flag applies to. | ||
flag_flag:: |
function | Determines whether the user may flag, or unflag, the given entity. | ||
flag_flag:: |
function | Utility function: Checks whether a flag applies to a certain type, and possibly subtype, of entity. | ||
flag_flag:: |
function | Determine access to multiple objects. | ||
flag_flag:: |
function | Returns administrative menu path for carrying out some action. | ||
flag_flag:: |
function | Returns TRUE if the flag applies to the entity with the given ID. | ||
flag_flag:: |
function | Default constructor. Loads the default options. | ||
flag_flag:: |
function | Deletes a flag from the database. | ||
flag_flag:: |
function | Disable a flag provided by a module. | ||
flag_flag:: |
function | Enable a flag provided by a module. | ||
flag_flag:: |
static | function | Create a complete flag (except an FID) from an array definition. | |
flag_flag:: |
static | function | Another factory method. Returns a new, "empty" flag; e.g., one suitable for the "Add new flag" page. | |
flag_flag:: |
static | function | Creates a flag from a database row. Returns it. | |
flag_flag:: |
function | Fetches, possibly from some cache, an entity this flag works with. | ||
flag_flag:: |
function | Load this flag's role data from permissions. | ||
flag_flag:: |
function | Finds the "default flag" corresponding to this flag. | ||
flag_flag:: |
function | Flags, or unflags, an item. | 1 | |
flag_flag:: |
private | function | Unflag an entity by deleting a Flagging. | |
flag_flag:: |
private | function | Create a new Flagging to flag an entity. | |
flag_flag:: |
private | function | Update a Flagging. | |
flag_flag:: |
function | Returns the number of times an item is flagged. | ||
flag_flag:: |
function | Returns an array of errors set during validation. | ||
flag_flag:: |
function | Similar to is_flagged() excepts it returns the flagging entity. | ||
flag_flag:: |
function | Returns the flagging record. | 2 | |
flag_flag:: |
function | Processes a flag label for display. This means language translation and token replacements. | ||
flag_flag:: |
function | Get the link type for this flag. | ||
flag_flag:: |
function | Options are stored serialized in the database. | ||
flag_flag:: |
function | A convenience method for getting the flag title. | ||
flag_flag:: |
function | Returns the number of items a user has flagged. | ||
flag_flag:: |
function | Returns an array of all actions that are executable with this flag. | ||
flag_flag:: |
function | Saves a new flag to the database. Better use save(). | ||
flag_flag:: |
function | Returns TRUE if this flag's declared API version is compatible with this module. | ||
flag_flag:: |
function | Determines if a certain user has flagged this object. | ||
flag_flag:: |
function | Construct a new, empty flagging entity object. | ||
flag_flag:: |
function | Store an object in the flag handler's cache. | ||
flag_flag:: |
function | Reverts an overriding flag to its default state. | ||
flag_flag:: |
function | Saves a flag to the database. It is a wrapper around update() and insert(). | ||
flag_flag:: |
function | Renders a flag/unflag link. | ||
flag_flag:: |
function | Provides an array of possible themes to try for a given flag. | ||
flag_flag:: |
function | Saves an existing flag to the database. Better use save(). | ||
flag_flag:: |
function | Determines whether the user has the permission to use this flag. | ||
flag_flag:: |
function | Returns TRUE if this flag requires anonymous user cookies. | ||
flag_flag:: |
function | Validates this flag's options. | ||
flag_flag:: |
function | Validates that the current flag's access settings are valid. | ||
flag_flag:: |
function | Validates that the current flag's name is valid. | ||
flag_flag:: |
function | Decreases the flag count for an object and clears the static counts cache. | ||
flag_flag:: |
function | Set a cookie for anonymous users to record their flagging. | ||
flag_flag:: |
function | A shortcut function to output the link URL. | ||
flag_flag:: |
function | Increases the flag count for an object and clears the static counts cache. | ||
flag_flag:: |
function | Determines if a certain user has flagged this object. | ||
flag_flag:: |
function | Remove the cookie for anonymous users to record their unflagging. | ||
flag_user:: |
function |
Update the flag with settings entered in a form. Overrides flag_flag:: |
||
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 |
Implements access() implemented by each child class. Overrides flag_flag:: |
||
flag_user:: |
function |
Implements access_multiple() implemented by each child class. Overrides flag_flag:: |