You are here

public function Flag::isFlagged in Flag 8.4

Returns true of there's a flagging for this flag and the given entity.

Parameters

EntityInterface $entity: The flaggable entity.

AccountInterface $account: (optional) The account of the user that flagged the entity.

string $session_id: (optional) The session ID. This must be supplied if $account is the anonymous user.

Return value

bool True if the given entity is flagged, FALSE otherwise.

Throws

\LogicException Thrown when $account is anonymous but no associated session ID is specified.

Overrides FlagInterface::isFlagged

File

src/Entity/Flag.php, line 200

Class

Flag
Provides the Flag configuration entity.

Namespace

Drupal\flag\Entity

Code

public function isFlagged(EntityInterface $entity, AccountInterface $account = NULL, $session_id = NULL) {
  \Drupal::service('flag')
    ->populateFlaggerDefaults($account, $session_id);

  // Load the is flagged list from the flagging storage, check if this flag
  // is in the list.
  $flag_ids = \Drupal::entityTypeManager()
    ->getStorage('flagging')
    ->loadIsFlagged($entity, $account, $session_id);
  return isset($flag_ids[$this
    ->id()]);
}