Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ModulePermissionsLinkHelper.php

class ModulePermissionsLinkHelper

Provides a helper for generating module permissions links.

Hierarchy

  • class \Drupal\user\ModulePermissionsLinkHelper uses \Drupal\Core\StringTranslation\StringTranslationTrait

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(PermissionHandlerInterface $permissionHandler, AccessManagerInterface $accessManager, 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' => $this->t('Configure @module permissions', [
                        '@module' => $name,
                    ]),
                    'description' => '',
                    'url' => $url,
                ];
            }
        }
        return NULL;
    }

}

Members

Title Sort descending Modifiers Object type Summary
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.
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.
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal