You are here

class FlagPermissions in Flag 8.4

Provides dynamic permissions for defined flags.

Hierarchy

Expanded class hierarchy of FlagPermissions

File

src/Permissions/FlagPermissions.php, line 12

Namespace

Drupal\flag\Permissions
View 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

Namesort descending Modifiers Type Description Overrides
FlagPermissions::$flagService protected property The flag service.
FlagPermissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
FlagPermissions::permissions public function Returns an array of dynamic flag permissions.
FlagPermissions::__construct public function Constructs a FlagPermissions instance.