class ModulePermissionsLinkHelper

Same name and namespace in other branches
  1. 11.x core/modules/user/src/ModulePermissionsLinkHelper.php \Drupal\user\ModulePermissionsLinkHelper

Provides a helper for generating module permissions links.

Hierarchy

Expanded class hierarchy of ModulePermissionsLinkHelper

2 files declare their use of ModulePermissionsLinkHelper
AdminController.php in core/modules/system/src/Controller/AdminController.php
HelpController.php in core/modules/help/src/Controller/HelpController.php
1 string reference to 'ModulePermissionsLinkHelper'
user.services.yml in core/modules/user/user.services.yml
core/modules/user/user.services.yml
1 service uses ModulePermissionsLinkHelper
user.module_permissions_link_helper in core/modules/user/user.services.yml
Drupal\user\ModulePermissionsLinkHelper

File

core/modules/user/src/ModulePermissionsLinkHelper.php, line 15

Namespace

Drupal\user
View source
class ModulePermissionsLinkHelper {
  use StringTranslationTrait;
  
  /**
   * Constructs a new service instance.
   *
   * @param \Drupal\user\PermissionHandlerInterface $permissionHandler
   *   The user permissions handler service.
   * @param \Drupal\Core\Access\AccessManagerInterface $accessManager
   *   The access manager service.
   * @param \Drupal\Core\Extension\ModuleExtensionList $moduleExtensionList
   *   The module handler service.
   */
  public function __construct(protected PermissionHandlerInterface $permissionHandler, protected AccessManagerInterface $accessManager, protected ModuleExtensionList $moduleExtensionList) {
  }
  
  /**
   * Generates a link pointing to a given module's permissions page section.
   *
   * @param string $module
   *   The module name.
   * @param string $name
   *   The module display name.
   *
   * @return array|null
   *   A module permissions link as a render array or NULL if the module doesn't
   *   expose any permission or the current user cannot access it.
   */
  public function getModulePermissionsLink(string $module, string $name) : ?array {
    if ($this->permissionHandler
      ->moduleProvidesPermissions($module)) {
      if ($this->accessManager
        ->checkNamedRoute('user.admin_permissions.module', [
        'modules' => $module,
      ])) {
        $url = new Url('user.admin_permissions.module', [
          'modules' => $module,
        ]);
        return [
          'title' => t('Configure @module permissions', [
            '@module' => $name,
          ]),
          'description' => '',
          'url' => $url,
        ];
      }
    }
    return NULL;
  }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
ModulePermissionsLinkHelper::getModulePermissionsLink public function Generates a link pointing to a given module's permissions page section.
ModulePermissionsLinkHelper::__construct public function Constructs a new service instance.
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
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.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.