You are here

public function FlagServiceInterface::getEntityFlaggings in Flag 8.4

Get flaggings for the given entity, flag, and optionally, user.

This method works very much like FlagServiceInterface::getFlagging() only it returns all flaggings matching the given parameters.

$flag = \Drupal::service('flag')
  ->getFlagById('bookmark');
$node = Node::load($node_id);
$flaggings = \Drupal::service('flag')
  ->getEntityFlaggings($flag, $node);
foreach ($flaggings as $flagging) {

  // Do something with each flagging.
}

Parameters

\Drupal\flag\FlagInterface $flag: The flag entity.

\Drupal\Core\Entity\EntityInterface $entity: The flaggable entity.

\Drupal\Core\Session\AccountInterface $account: (optional) The account of the flagging user. If NULL, flaggings for any user will be returned.

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

Return value

array An array of flaggings.

Throws

\LogicException An exception is thrown if the given $account is anonymous, but no $session_id is given.

1 method overrides FlagServiceInterface::getEntityFlaggings()
FlagService::getEntityFlaggings in src/FlagService.php
Get flaggings for the given entity, flag, and optionally, user.

File

src/FlagServiceInterface.php, line 107

Class

FlagServiceInterface
Flag service interface.

Namespace

Drupal\flag

Code

public function getEntityFlaggings(FlagInterface $flag, EntityInterface $entity, AccountInterface $account = NULL, $session_id = NULL);