You are here

class FlagListsPermissionHandler in Flag Lists 4.0.x

Hierarchy

Expanded class hierarchy of FlagListsPermissionHandler

1 string reference to 'FlagListsPermissionHandler'
flag_lists.services.yml in ./flag_lists.services.yml
flag_lists.services.yml
1 service uses FlagListsPermissionHandler
flag_lists.user.permissions in ./flag_lists.services.yml
Drupal\flag_lists\Permissions\FlagListsPermissionHandler

File

src/Permissions/FlagListsPermissionHandler.php, line 15

Namespace

Drupal\flag_lists\Permissions
View source
class FlagListsPermissionHandler extends PermissionHandler {
  use StringTranslationTrait;

  /**
   * The Flag Lists Service.
   *
   * @var \Drupal\flag_lists\FlagListsServiceInterface
   */
  protected $flagListsService;

  /**
   * Constructs a new PermissionHandler.
   *
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler.
   * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
   *   The string translation.
   * @param \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver
   *   The controller resolver.
   * @param \Drupal\flag_lists\FlagListsServiceInterface $flag_lists_service
   *   The Flag Lists Service.
   */
  public function __construct(ModuleHandlerInterface $module_handler, TranslationInterface $string_translation, ControllerResolverInterface $controller_resolver, FlagListsServiceInterface $flag_lists_service) {
    parent::__construct($module_handler, $string_translation, $controller_resolver);
    $this->flagListsService = $flag_lists_service;
  }

  /**
   * {@inheritdoc}
   */
  public function getPermissions() {
    $all_permissions = $this
      ->buildPermissionsYaml();

    // Remove the possible long list of unused flag permissions
    // due to the flag lists module.
    $flagLists = $this->flagListsService
      ->getAllFlaggingCollections();
    foreach ($flagLists as $flagList) {
      $flag = 'flag ' . $flagList
        ->getRelatedFlag()
        ->id();
      $unflag = 'unflag ' . $flagList
        ->getRelatedFlag()
        ->id();
      unset($all_permissions[$flag]);
      unset($all_permissions[$unflag]);
    }

    // Check for access for the used template as well.
    $flagTemplates = $this->flagListsService
      ->getAllFlagForList();
    foreach ($flagTemplates as $flagTemplate) {

      // Do we really want to remove the templates from
      // the possibility of setting them separately?
      $flag = 'flag ' . $flagTemplate
        ->id();
      $unflag = 'unflag ' . $flagTemplate
        ->id();
      unset($all_permissions[$flag]);
      unset($all_permissions[$unflag]);
    }
    return $this
      ->sortPermissions($all_permissions);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FlagListsPermissionHandler::$flagListsService protected property The Flag Lists Service.
FlagListsPermissionHandler::getPermissions public function Gets all available permissions. Overrides PermissionHandler::getPermissions
FlagListsPermissionHandler::__construct public function Constructs a new PermissionHandler. Overrides PermissionHandler::__construct
PermissionHandler::$controllerResolver protected property The controller resolver.
PermissionHandler::$moduleHandler protected property The module handler.
PermissionHandler::$yamlDiscovery protected property The YAML discovery class to find all .permissions.yml files.
PermissionHandler::buildPermissionsYaml protected function Builds all permissions provided by .permissions.yml files.
PermissionHandler::getModuleNames protected function Returns all module names.
PermissionHandler::getYamlDiscovery protected function Gets the YAML discovery.
PermissionHandler::moduleProvidesPermissions public function Determines whether a module provides some permissions. Overrides PermissionHandlerInterface::moduleProvidesPermissions
PermissionHandler::sortPermissions protected function Sorts the given permissions by provider name and title.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.