public function FlagService::getAllFlags in Flag 8.4
List all flags available.
For example to list all flags operating on articles:
$this->flagService
->getAllFlags('node', 'article');
If all the parameters are omitted, a list of all flags will be returned.
Note that this does not check for any kind of access.
Parameters
string $entity_type: (optional) The type of entity for which to load the flags.
string $bundle: (optional) The bundle for which to load the flags.
Return value
\Drupal\flag\FlagInterface[] An array of flag entities, keyed by the entity IDs.
Overrides FlagServiceInterface::getAllFlags
File
- src/
FlagService.php, line 61
Class
- FlagService
- Flag service.
Namespace
Drupal\flagCode
public function getAllFlags($entity_type = NULL, $bundle = NULL) {
$query = $this->entityTypeManager
->getStorage('flag')
->getQuery();
if ($entity_type != NULL) {
$query
->condition('entity_type', $entity_type);
}
$ids = $query
->execute();
$flags = $this
->getFlagsByIds($ids);
if (isset($bundle)) {
$flags = array_filter($flags, function (FlagInterface $flag) use ($bundle) {
$bundles = $flag
->getApplicableBundles();
return in_array($bundle, $bundles);
});
}
return $flags;
}