You are here

public function FlagListsService::getUsersFlagForList in Flag Lists 8

Same name and namespace in other branches
  1. 4.0.x src/FlagListsService.php \Drupal\flag_lists\FlagListsService::getUsersFlagForList()

Get a user's Flag For List, i.e. all Flags tagged as available.

NOT used nor tested!

Parameters

Drupal\Core\Session\AccountInterface $account: The wanted user's account.

string $entity_type: The wanted entity type.

string $bundle: The wanted bundle of the entity.

Return value

Drupal\flag_lists\Entity\FlagForList[] An array of Flag For Lists that the account has access to.

File

src/FlagListsService.php, line 142

Class

FlagListsService
Class FlagForList service.

Namespace

Drupal\flag_lists

Code

public function getUsersFlagForList(AccountInterface $account, $entity_type = NULL, $bundle = NULL) {
  $flagForList = $this
    ->getAllFlagForList($entity_type, $bundle);
  $filteredFlagForList = [];
  foreach ($flagForList as $flag_id => $flag) {
    if ($flag
      ->actionAccess('flag', $account)
      ->isAllowed() || $flag
      ->actionAccess('unflag', $account)
      ->isAllowed()) {
      $filteredFlagForList[$flag_id] = $flag;
    }
  }
  return $filteredFlagForList;
}