You are here

class PermissionProvider in GraphQL 8.4

Provides access control permissions for all exposed GraphQL servers.

Hierarchy

Expanded class hierarchy of PermissionProvider

1 string reference to 'PermissionProvider'
graphql.services.yml in ./graphql.services.yml
graphql.services.yml
1 service uses PermissionProvider
graphql.permission_provider in ./graphql.services.yml
Drupal\graphql\PermissionProvider

File

src/PermissionProvider.php, line 11

Namespace

Drupal\graphql
View source
class PermissionProvider {
  use StringTranslationTrait;

  /**
   * The entity type manager service.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * PermissionProvider constructor.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
   */
  public function __construct(EntityTypeManagerInterface $entityTypeManager) {
    $this->entityTypeManager = $entityTypeManager;
  }

  /**
   * Collects permissions for the server endpoints.
   */
  public function permissions() : array {
    $storage = $this->entityTypeManager
      ->getStorage('graphql_server');

    /** @var \Drupal\graphql\Entity\ServerInterface[] $servers */
    $servers = $storage
      ->loadMultiple();
    $permissions = [];
    foreach ($servers as $id => $server) {
      $params = [
        '%name' => $server
          ->label(),
      ];
      $permissions["execute {$id} arbitrary graphql requests"] = [
        'title' => $this
          ->t('%name: Execute arbitrary requests', $params),
        'description' => $this
          ->t('Allows users to execute arbitrary requests on the %name endpoint.', $params),
      ];
      $permissions["execute {$id} persisted graphql requests"] = [
        'title' => $this
          ->t('%name: Execute persisted requests', $params),
        'description' => $this
          ->t('Allows users to execute persisted requests on the %name endpoint.', $params),
      ];
      $permissions["use {$id} graphql explorer"] = [
        'title' => $this
          ->t('%name: Use explorer', $params),
        'description' => $this
          ->t('Allows users use the explorer interface.', $params),
      ];
      $permissions["use {$id} graphql voyager"] = [
        'title' => $this
          ->t('%name: Use voyager', $params),
        'description' => $this
          ->t('Allows users to use the voyager interface.', $params),
      ];
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PermissionProvider::$entityTypeManager protected property The entity type manager service.
PermissionProvider::permissions public function Collects permissions for the server endpoints.
PermissionProvider::__construct public function PermissionProvider constructor.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
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.