You are here

public function FlagServiceInterface::getFlaggingUsers in Flag 8.4

Get a list of users that have flagged an entity.

$flag = \Drupal::service('flag')
  ->getFlagById('bookmark');
$node = Node::load($node_id);
$flagging_users = \Drupal::service('flag')
  ->getFlaggingUsers($node, $flag);
foreach ($flagging_users as $user) {

  // Do something.
}

Parameters

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

\Drupal\flag\FlagInterface $flag: (optional) The flag entity to which to restrict results.

Return value

array An array of users who have flagged the entity.

1 method overrides FlagServiceInterface::getFlaggingUsers()
FlagService::getFlaggingUsers in src/FlagService.php
Get a list of users that have flagged an entity.

File

src/FlagServiceInterface.php, line 184

Class

FlagServiceInterface
Flag service interface.

Namespace

Drupal\flag

Code

public function getFlaggingUsers(EntityInterface $entity, FlagInterface $flag = NULL);