You are here

protected function FlagListBuilder::getFlagRoles in Flag 8.4

Creates a render array of roles that may use the flag.

Parameters

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

Return value

array A render array of flag roles for the entity.

1 call to FlagListBuilder::getFlagRoles()
FlagListBuilder::buildRow in src/Controller/FlagListBuilder.php
Builds a row for an entity in the entity listing.

File

src/Controller/FlagListBuilder.php, line 49

Class

FlagListBuilder
Provides a entity list page for Flags.

Namespace

Drupal\flag\Controller

Code

protected function getFlagRoles(FlagInterface $flag) {
  $all_roles = [];
  foreach (array_keys($flag
    ->actionPermissions()) as $perm) {
    $roles = user_roles(FALSE, $perm);
    foreach ($roles as $rid => $role) {
      $all_roles[$rid] = $role
        ->label();
    }
  }
  $out = implode(', ', $all_roles);
  if (empty($out)) {
    return [
      '#markup' => '<em>' . $this
        ->t('None') . '</em>',
      '#allowed_tags' => [
        'em',
      ],
    ];
  }
  return [
    '#markup' => rtrim($out, ', '),
  ];
}