Commit 6e466e49 authored by alexpott's avatar alexpott

Issue #2474055 by dawehner, pwolanin: Performance regression in contact_help()

parent 76ca5b08
......@@ -13,12 +13,12 @@
* Implements hook_help().
*/
function contact_help($route_name, RouteMatchInterface $route_match) {
$menu_page = \Drupal::moduleHandler()->moduleExists('menu_ui') ? \Drupal::url('entity.menu.collection') : '#';
$block_page = \Drupal::moduleHandler()->moduleExists('block') ? \Drupal::url('block.admin_display') : '#';
$contact_page = \Drupal::url('entity.contact_form.collection');
switch ($route_name) {
case 'help.page.contact':
$menu_page = \Drupal::moduleHandler()->moduleExists('menu_ui') ? \Drupal::url('entity.menu.collection') : '#';
$block_page = \Drupal::moduleHandler()->moduleExists('block') ? \Drupal::url('block.admin_display') : '#';
$contact_page = \Drupal::url('entity.contact_form.collection');
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Contact module allows visitors to contact registered users on your site, using the personal contact form, and also allows you to set up site-wide contact forms. For more information, see the <a href="!contact">online documentation for the Contact module</a>.', array('!contact' => 'https://www.drupal.org/documentation/modules/contact')) . '</p>';
......@@ -36,6 +36,8 @@ function contact_help($route_name, RouteMatchInterface $route_match) {
return $output;
case 'entity.contact_form.collection':
$menu_page = \Drupal::moduleHandler()->moduleExists('menu_ui') ? \Drupal::url('entity.menu.collection') : '#';
$block_page = \Drupal::moduleHandler()->moduleExists('block') ? \Drupal::url('block.admin_display') : '#';
$output = '';
$output .= '<p>' . t('The <em>Personal contact form</em> is the form for site visitors to contact registered users; the name and recipients of this form cannot be edited. Other forms listed here are your configured site-wide contact forms, which site visitors can use to send mail to a centralized email address or addresses. You can edit the name and recipients of site-wide forms by choosing the <em>Edit</em> operation. You can also configure the fields and display of both personal and site-wide forms.') . '</p>';
$output .= '<p>' . t('If you have configured a default site-wide contact form, a <em>Contact</em> menu link in the <em>Footer</em> menu will link to it. You can modify this link from the <a href="!menu-settings">Menus page</a> if you have the Menu UI module installed. You can also create links to other contact forms; the URL has format contact/machine_name_of_form.', array('!menu-settings' => $menu_page)) . '</p>';
......
<?php
/**
* @file
* Contains \Drupal\help\Tests\HelpEmptyPageTest.
*/
namespace Drupal\help\Tests;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Routing\RouteMatch;
use Drupal\help_test\SuperNovaGenerator;
use Drupal\simpletest\KernelTestBase;
/**
* Tests the empty HTML page.
*
* @group help
*/
class HelpEmptyPageTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['system', 'help_test', 'user'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installSchema('system', 'router');
}
/**
* {@inheritdoc}
*/
public function containerBuild(ContainerBuilder $container) {
parent::containerBuild($container);
$container->set('url_generator', new SupernovaGenerator());
}
/**
* Ensures that no URL generator is called on a page without hook_help().
*/
public function testEmptyHookHelp() {
$all_modules = system_rebuild_module_data();
$all_modules = array_filter($all_modules, function ($module) {
// Filter contrib, hidden, already enabled modules and modules in the
// Testing package.
if ($module->origin !== 'core' || !empty($module->info['hidden']) || $module->status == TRUE || $module->info['package'] == 'Testing') {
return FALSE;
}
return TRUE;
});
\Drupal::service('module_installer')->install(array_keys($all_modules));
$route = \Drupal::service('router.route_provider')->getRouteByName('<front>');
\Drupal::service('module_handler')->invokeAll('help', ['<front>', new RouteMatch('<front>', $route)]);
}
}
name: help_test
type: module
core: 8.x
dependencies:
- help
<?php
/**
* @file
* Contains \Drupal\help_test\SuperNovaGenerator.
*/
namespace Drupal\help_test;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Symfony\Component\Routing\RequestContext;
/**
* Implements a URL generator which always thrown an exception.
*/
class SuperNovaGenerator implements UrlGeneratorInterface {
/**
* {@inheritdoc}
*/
public function setContext(RequestContext $context) {
throw new \Exception();
}
/**
* {@inheritdoc}
*/
public function getContext() {
throw new \Exception();
}
/**
* {@inheritdoc}
*/
public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH) {
throw new \Exception();
}
/**
* {@inheritdoc}
*/
public function generateFromPath($path = NULL, $options = array()) {
throw new \Exception();
}
/**
* {@inheritdoc}
*/
public function getPathFromRoute($name, $parameters = array()) {
throw new \Exception();
}
/**
* {@inheritdoc}
*/
public function generateFromRoute($name, $parameters = array(), $options = array()) {
throw new \Exception();
}
/**
* {@inheritdoc}
*/
public function supports($name) {
throw new \Exception();
}
/**
* {@inheritdoc}
*/
public function getRouteDebugMessage($name, array $parameters = array()) {
throw new \Exception();
}
}
......@@ -1136,11 +1136,12 @@ function user_role_change_permissions($rid, array $permissions = array()) {
*/
function user_role_grant_permissions($rid, array $permissions = array()) {
// Grant new permissions for the role.
$role = Role::load($rid);
foreach ($permissions as $permission) {
$role->grantPermission($permission);
if ($role = Role::load($rid)) {
foreach ($permissions as $permission) {
$role->grantPermission($permission);
}
$role->save();
}
$role->save();
}
/**
......
......@@ -479,8 +479,7 @@ public function calculateDependencies() {
$dependencies = parent::calculateDependencies();
$menu = $this->getOption('menu');
if ($menu['type'] === 'normal') {
$menu_entity = $this->menuStorage->load($menu['menu_name']);
if ($menu['type'] === 'normal' && ($menu_entity = $this->menuStorage->load($menu['menu_name']))) {
$dependencies[$menu_entity->getConfigDependencyKey()][] = $menu_entity->getConfigDependencyName();
}
......
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