You are here

function flag_node::flag in Flag 7.3

Same name and namespace in other branches
  1. 5 flag.inc \flag_node::flag()
  2. 6.2 flag.inc \flag_node::flag()
  3. 6 flag.inc \flag_node::flag()
  4. 7.2 flag.inc \flag_node::flag()

Flags, or unflags, an item.

Parameters

string $action: Either 'flag' or 'unflag'.

int $entity_id: The ID of the item to flag or unflag.

string|NULL $account: The user on whose behalf to flag. Leave empty for the current user.

bool $skip_permission_check: Flag the item even if the $account user don't have permission to do so.

$flagging: (optional) This method works in tandem with Drupal's Field subsystem. Pass in a Flagging entity if you want operate on it as well. This may be used either of the following cases:

  • to save field data on a new Flagging entity at the same time as flagging an entity. In this case, using Entity API's entity_create() is recommended, although the Flagging entity may also be created directly as a new stdClass object.
  • to update field data an existing flagging. The $action parameter should be set to 'flag'. The Flagging entity will need to be loaded first with flagging_load().

As with Drupal core API functions for saving entities, no validation of Field API fields is performed here. It is the responsibility of the caller to take care of Field API validation, using either field_attach_form_validate() or field_attach_validate().

Return value

bool FALSE if some error occured (e.g., user has no permission, flag isn't applicable to the item, etc.), TRUE otherwise.

Overrides flag_flag::flag

File

includes/flag/flag_node.inc, line 106
Contains the flag_node class.

Class

flag_node
Implements a node flag.

Code

function flag($action, $entity_id, $account = NULL, $skip_permission_check = FALSE, $flagging = NULL) {
  $entity_id = $this
    ->get_translation_id($entity_id);
  return parent::flag($action, $entity_id, $account, $skip_permission_check, $flagging);
}