You are here

private function flag_flag::flagging_insert in Flag 7.3

Create a new Flagging to flag an entity.

Parameters

$flagging: The flagging entity that is to be saved.

$entity_id: The entity ID of entity being flagged.

$account: The account performing the flagging.

1 call to flag_flag::flagging_insert()
flag_flag::flag in includes/flag/flag_flag.inc
Flags, or unflags, an item.

File

includes/flag/flag_flag.inc, line 811
Contains the flag_flag class. Flag type classes use an object oriented style inspired by that of Views 2.

Class

flag_flag
This abstract class represents a flag, or, in Views 2 terminology, "a handler".

Code

private function flagging_insert($flagging, $entity_id, $account) {
  if ($this
    ->uses_anonymous_cookies()) {
    $this
      ->_flag_anonymous($entity_id);
  }

  // Invoke presave hooks.
  field_attach_presave('flagging', $flagging);

  // Invoke hook_entity_presave().
  module_invoke_all('entity_presave', $flagging, 'flagging');

  // Set the timestamp.
  $flagging->timestamp = REQUEST_TIME;

  // Save the flagging entity.
  drupal_write_record('flagging', $flagging);

  // Clear various caches; we don't want code running after us to report
  // wrong counts or false flaggings.
  drupal_static_reset('flag_get_user_flags');
  drupal_static_reset('flag_get_entity_flags');

  // Despite being named in the same pattern as the count API functions, these
  // query the {flagging} table, so are reset here.
  drupal_static_reset('flag_get_entity_flag_counts');
  drupal_static_reset('flag_get_user_flag_counts');
  $this
    ->_increase_count($entity_id);

  // We're writing out a flagging entity even when we aren't passed one
  // (e.g., when flagging via JavaScript toggle links); in this case
  // Field API will assign the fields their default values.
  // Invoke insert hooks.
  field_attach_insert('flagging', $flagging);

  // Invoke hook_entity_insert().
  module_invoke_all('entity_insert', $flagging, 'flagging');
  module_invoke_all('flag_flag', $this, $entity_id, $account, $flagging);

  // Invoke Rules event.
  if (module_exists('rules')) {
    $this
      ->invoke_rules_event('flag', $flagging, $entity_id, $account);
  }
}