class FlagPermissions in Flag 8.4
Provides dynamic permissions for defined flags.
Hierarchy
- class \Drupal\flag\Permissions\FlagPermissions implements ContainerInjectionInterface
Expanded class hierarchy of FlagPermissions
File
- src/
Permissions/ FlagPermissions.php, line 12
Namespace
Drupal\flag\PermissionsView source
class FlagPermissions implements ContainerInjectionInterface {
/**
* The flag service.
*
* @var \Drupal\flag\FlagServiceInterface
*/
protected $flagService;
/**
* Constructs a FlagPermissions instance.
*
* @param FlagServiceInterface $flag
* The flag service.
*/
public function __construct(FlagServiceInterface $flag) {
$this->flagService = $flag;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('flag'));
}
/**
* Returns an array of dynamic flag permissions.
*
* @return array
* An array of permissions.
*
* @see Drupal\flag\FlagInterface::getPermissions().
*/
public function permissions() {
$permissions = [];
// Get a list of flags from the FlagService.
$flags = $this->flagService
->getAllFlags();
// Provide flag and unflag permissions for each flag.
foreach ($flags as $flag_name => $flag) {
$permissions += $flag
->actionPermissions();
}
return $permissions;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FlagPermissions:: |
protected | property | The flag service. | |
FlagPermissions:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
FlagPermissions:: |
public | function | Returns an array of dynamic flag permissions. | |
FlagPermissions:: |
public | function | Constructs a FlagPermissions instance. |