Issue #2527546 by DuaelFr, larowlan, chx: ModulesListForm::buildRow() does not properly build the Request object for the TitleResolver

8.0.x
Alex Pott 2015-10-05 12:52:28 +01:00
parent 79a12423a7
commit 19167f7210
2 changed files with 3 additions and 66 deletions

View File

@ -59,34 +59,6 @@ class ModulesListForm extends FormBase {
*/
protected $keyValueExpirable;
/**
* The title resolver.
*
* @var \Drupal\Core\Controller\TitleResolverInterface
*/
protected $titleResolver;
/**
* The route provider.
*
* @var \Drupal\Core\Routing\RouteProviderInterface
*/
protected $routeProvider;
/**
* The current route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/**
* The menu link manager.
*
* @var \Drupal\Core\Menu\MenuLinkManagerInterface
*/
protected $menuLinkManager;
/**
* The module installer.
*
@ -111,10 +83,6 @@ class ModulesListForm extends FormBase {
$container->get('keyvalue.expirable')->get('module_list'),
$container->get('access_manager'),
$container->get('current_user'),
$container->get('current_route_match'),
$container->get('title_resolver'),
$container->get('router.route_provider'),
$container->get('plugin.manager.menu.link'),
$container->get('user.permissions')
);
}
@ -132,27 +100,15 @@ class ModulesListForm extends FormBase {
* Access manager.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
* @param \Drupal\Core\Controller\TitleResolverInterface $title_resolver
* The title resolver.
* @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
* 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, PermissionHandlerInterface $permission_handler) {
public function __construct(ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, KeyValueStoreExpirableInterface $key_value_expirable, AccessManagerInterface $access_manager, AccountInterface $current_user, PermissionHandlerInterface $permission_handler) {
$this->moduleHandler = $module_handler;
$this->moduleInstaller = $module_installer;
$this->keyValueExpirable = $key_value_expirable;
$this->accessManager = $access_manager;
$this->currentUser = $current_user;
$this->routeMatch = $route_match;
$this->titleResolver = $title_resolver;
$this->routeProvider = $route_provider;
$this->menuLinkManager = $menu_link_manager;
$this->permissionHandler = $permission_handler;
}
@ -296,32 +252,13 @@ class ModulesListForm extends FormBase {
if ($module->status && isset($module->info['configure'])) {
$route_parameters = isset($module->info['configure_parameters']) ? $module->info['configure_parameters'] : array();
if ($this->accessManager->checkNamedRoute($module->info['configure'], $route_parameters, $this->currentUser)) {
$links = $this->menuLinkManager->loadLinksByRoute($module->info['configure']);
/** @var \Drupal\Core\Menu\MenuLinkInterface $link */
$link = reset($links);
// Most configure links have a corresponding menu link, though some just
// have a route.
if ($link) {
$description = $link->getDescription();
}
else {
$request = new Request();
$request->attributes->set('_route_name', $module->info['configure']);
$route_object = $this->routeProvider->getRouteByName($module->info['configure']);
$request->attributes->set('_route', $route_object);
$request->attributes->add($route_parameters);
$description = $this->titleResolver->getTitle($request, $route_object);
}
$row['links']['configure'] = array(
'#type' => 'link',
'#title' => $this->t('Configure'),
'#title' => $this->t('Configure <span class="visually-hidden">the @module module</span>', ['@module' => $module->info['name']]),
'#url' => Url::fromRoute($module->info['configure'], $route_parameters),
'#options' => array(
'attributes' => array(
'class' => array('module-link', 'module-link-configure'),
'title' => $description,
),
),
);

View File

@ -42,7 +42,7 @@ class ModulesListFormWebTest extends WebTestBase {
$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']");
$this->assertFieldByXPath("//a[contains(@href, '/system-test/configure/bar') and text()='Configure ']/span[contains(@class, 'visually-hidden') and text()='the System test module']");
// 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']");