Commit ef650e72 authored by catch's avatar catch

Issue #2147689 by Xano: [regression] Support route parameters for *info.yml...

Issue #2147689 by Xano: [regression] Support route parameters for *info.yml files' configure route name.
parent 26d253c7
......@@ -16,6 +16,7 @@
use Drupal\Core\Form\FormBase;
use Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Access\AccessManager;
......@@ -29,6 +30,13 @@
*/
class ModulesListForm extends FormBase {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* The module handler service.
*
......@@ -66,7 +74,8 @@ public static function create(ContainerInterface $container) {
$container->get('keyvalue.expirable')->get('module_list'),
$container->get('access_manager'),
$container->get('entity.manager'),
$container->get('entity.query')
$container->get('entity.query'),
$container->get('current_user')
);
}
......@@ -83,13 +92,16 @@ public static function create(ContainerInterface $container) {
* The entity manager.
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
* The entity query factory.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
*/
public function __construct(ModuleHandlerInterface $module_handler, KeyValueStoreExpirableInterface $key_value_expirable, AccessManager $access_manager, EntityManagerInterface $entity_manager, QueryFactory $query_factory) {
public function __construct(ModuleHandlerInterface $module_handler, KeyValueStoreExpirableInterface $key_value_expirable, AccessManager $access_manager, EntityManagerInterface $entity_manager, QueryFactory $query_factory, AccountInterface $current_user) {
$this->moduleHandler = $module_handler;
$this->keyValueExpirable = $key_value_expirable;
$this->accessManager = $access_manager;
$this->entityManager = $entity_manager;
$this->queryFactory = $query_factory;
$this->currentUser = $current_user;
}
/**
......@@ -226,7 +238,8 @@ protected function buildRow(array $modules, Extension $module, $distribution) {
// Generate link for module's configuration page, if it has one.
$row['links']['configure'] = array();
if ($module->status && isset($module->info['configure'])) {
if ($this->accessManager->checkNamedRoute($module->info['configure'], array(), \Drupal::currentUser())) {
$route_parameters = isset($module->info['configure_parameters']) ? $module->info['configure_parameters'] : array();
if ($this->accessManager->checkNamedRoute($module->info['configure'], $route_parameters, $this->currentUser)) {
$result = $this->queryFactory->get('menu_link')
->condition('route_name', $module->info['configure'])
->execute();
......@@ -236,6 +249,7 @@ protected function buildRow(array $modules, Extension $module, $distribution) {
'#type' => 'link',
'#title' => $this->t('Configure'),
'#route_name' => $module->info['configure'],
'#route_parameters' => $route_parameters,
'#options' => array(
'attributes' => array(
'class' => array('module-link', 'module-link-configure'),
......
<?php
/**
* @file
* Contains \Drupal\system\Form\ModulesListFormWebTest.
*/
namespace Drupal\system\Tests\Form;
use Drupal\simpletest\WebTestBase;
/**
* Tests \Drupal\system\Form\ModulesListForm.
*/
class ModulesListFormWebTest extends WebTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('system_test');
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'description' => 'Tests \Drupal\system\Form\ModulesListForm.',
'name' => '\Drupal\system\Form\ModulesListForm web test',
'group' => 'Module',
);
}
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
\Drupal::state()->set('system_test.module_hidden', FALSE);
}
/**
* Tests the module list form.
*/
public function testModuleListForm() {
$this->drupalLogin($this->drupalCreateUser(array('administer modules')));
$this->drupalGet('admin/modules');
$this->assertResponse('200');
// Check that system_test's configure link was rendered correctly.
$this->assertLinkByHref('configure/bar');
}
}
......@@ -5,3 +5,6 @@ package: Testing
version: VERSION
core: 8.x
hidden: true
configure: system_test.configure
configure_parameters:
foo: bar
......@@ -70,6 +70,9 @@ function system_test_system_info_alter(&$info, Extension $file, $type) {
if ($file->getName() == 'requirements1_test' || $file->getName() == 'requirements2_test') {
$info['hidden'] = FALSE;
}
if ($file->getName() == 'system_test') {
$info['hidden'] = \Drupal::state()->get('system_test.module_hidden', TRUE);
}
}
/**
......
......@@ -72,3 +72,8 @@ system_test.shutdown_functions:
_content: '\Drupal\system_test\Controller\SystemTestController::shutdownFunctions'
requirements:
_access: 'TRUE'
system_test.configure:
path: '/system-test/configure/{foo}'
requirements:
_access: 'TRUE'
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