diff --git a/core/modules/system/src/Form/ModulesListForm.php b/core/modules/system/src/Form/ModulesListForm.php index 173fcc7218a78b63b27ec39df041ff2d8b005ff9..73b32ec932c94de26a739ce347112ca758f26e1a 100644 --- a/core/modules/system/src/Form/ModulesListForm.php +++ b/core/modules/system/src/Form/ModulesListForm.php @@ -24,6 +24,7 @@ use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteProviderInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\user\PermissionHandlerInterface; use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -94,6 +95,13 @@ class ModulesListForm extends FormBase { */ protected $moduleInstaller; + /** + * The permission handler. + * + * @var \Drupal\user\PermissionHandlerInterface + */ + protected $permissionHandler; + /** * {@inheritdoc} */ @@ -107,7 +115,8 @@ public static function create(ContainerInterface $container) { $container->get('current_route_match'), $container->get('title_resolver'), $container->get('router.route_provider'), - $container->get('plugin.manager.menu.link') + $container->get('plugin.manager.menu.link'), + $container->get('user.permissions') ); } @@ -132,8 +141,10 @@ public static function create(ContainerInterface $container) { * The route provider. * @param \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager * The menu link manager. + * @param \Drupal\user\PermissionHandlerInterface $permission_handler + * The permission handler. */ - public function __construct(ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, KeyValueStoreExpirableInterface $key_value_expirable, AccessManagerInterface $access_manager, AccountInterface $current_user, RouteMatchInterface $route_match, TitleResolverInterface $title_resolver, RouteProviderInterface $route_provider, MenuLinkManagerInterface $menu_link_manager) { + public function __construct(ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, KeyValueStoreExpirableInterface $key_value_expirable, AccessManagerInterface $access_manager, AccountInterface $current_user, RouteMatchInterface $route_match, TitleResolverInterface $title_resolver, RouteProviderInterface $route_provider, MenuLinkManagerInterface $menu_link_manager, PermissionHandlerInterface $permission_handler) { $this->moduleHandler = $module_handler; $this->moduleInstaller = $module_installer; $this->keyValueExpirable = $key_value_expirable; @@ -143,6 +154,7 @@ public function __construct(ModuleHandlerInterface $module_handler, ModuleInstal $this->titleResolver = $title_resolver; $this->routeProvider = $route_provider; $this->menuLinkManager = $menu_link_manager; + $this->permissionHandler = $permission_handler; } /** @@ -270,7 +282,7 @@ protected function buildRow(array $modules, Extension $module, $distribution) { // Generate link for module's permission, if the user has access to it. $row['links']['permissions'] = array(); - if ($module->status && \Drupal::currentUser()->hasPermission('administer permissions') && in_array($module->getName(), $this->moduleHandler->getImplementations('permission'))) { + if ($module->status && $this->currentUser->hasPermission('administer permissions') && $this->permissionHandler->moduleProvidesPermissions($module->getName())) { $row['links']['permissions'] = array( '#type' => 'link', '#title' => $this->t('Permissions'), diff --git a/core/modules/system/src/Tests/Form/ModulesListFormWebTest.php b/core/modules/system/src/Tests/Form/ModulesListFormWebTest.php index f0945ed99e203a12202f719429f100d9e32df6d7..3600364f186b5b918fa75f8c99071206570e2b00 100644 --- a/core/modules/system/src/Tests/Form/ModulesListFormWebTest.php +++ b/core/modules/system/src/Tests/Form/ModulesListFormWebTest.php @@ -33,11 +33,19 @@ protected function setUp() { * Tests the module list form. */ public function testModuleListForm() { - $this->drupalLogin($this->drupalCreateUser(array('administer modules'))); + $this->drupalLogin( + $this->drupalCreateUser( + array('administer modules', 'administer permissions') + ) + ); $this->drupalGet('admin/modules'); $this->assertResponse('200'); // Check that system_test's configure link was rendered correctly. $this->assertFieldByXPath("//a[contains(@href, '/system-test/configure/bar') and @title='Bar.bar']"); + + // Check that system_test's permissions link was rendered correctly. + $this->assertFieldByXPath("//a[contains(@href, '/admin/people/permissions#module-system_test') and @title='Configure permissions']"); } + } diff --git a/core/modules/system/tests/modules/system_test/system_test.permissions.yml b/core/modules/system/tests/modules/system_test/system_test.permissions.yml new file mode 100644 index 0000000000000000000000000000000000000000..fd06c57f49bcaede6223e11ecc21b99748528e9f --- /dev/null +++ b/core/modules/system/tests/modules/system_test/system_test.permissions.yml @@ -0,0 +1,2 @@ +system test: + title: 'Administer system test' \ No newline at end of file