Commit f96deaa5 authored by webchick's avatar webchick

Issue #2513626 by cilefen, akalata, Les Lim: [Regression] Module permission...

Issue #2513626 by cilefen, akalata, Les Lim: [Regression] Module permission links missing from module list page
parent 40335e97
......@@ -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'),
......
......@@ -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']");
}
}
system test:
title: 'Administer system test'
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment