You are here

class LanguageAccessPermissions in Language access 8

Provides language module permissions.

Hierarchy

Expanded class hierarchy of LanguageAccessPermissions

1 file declares its use of LanguageAccessPermissions
LanguageAccessPermissionsTest.php in tests/src/Kernel/LanguageAccessPermissionsTest.php

File

src/LanguageAccessPermissions.php, line 12

Namespace

Drupal\language_access
View source
class LanguageAccessPermissions implements ContainerInjectionInterface {

  /**
   * The REST resource config storage.
   *
   * @var \Drupal\Core\Language\LanguageManagerInterface
   */
  protected $languageManager;

  /**
   * Constructs a new LanguageAccessPermissions instance.
   *
   * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
   *   The language manager.
   */
  public function __construct(LanguageManagerInterface $language_manager) {
    $this->languageManager = $language_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('language_manager'));
  }

  /**
   * Returns an array of language access permissions.
   *
   * @return array
   *   Permissions.
   */
  public function permissions() {
    $permissions = [];
    $languages = $this->languageManager
      ->getLanguages();
    foreach ($languages as $language) {
      $permissions['access language ' . $language
        ->getId()] = [
        'title' => t('Access language @language', [
          '@language' => $language
            ->getName(),
        ]),
      ];
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LanguageAccessPermissions::$languageManager protected property The REST resource config storage.
LanguageAccessPermissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
LanguageAccessPermissions::permissions public function Returns an array of language access permissions.
LanguageAccessPermissions::__construct public function Constructs a new LanguageAccessPermissions instance.