Move into nested docroot

This commit is contained in:
Rob Davies 2017-02-13 15:31:17 +00:00
parent 83a0d3a149
commit c8b70abde9
13405 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,80 @@
<?php
/**
* @file
* Hooks for the Help system.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Provide online user help.
*
* By implementing hook_help(), a module can make documentation available to
* the user for the module as a whole, or for specific pages. Help for
* developers should usually be provided via function header comments in the
* code, or in special API example files.
*
* The page-specific help information provided by this hook appears in the
* Help block (provided by the core Help module), if the block is displayed on
* that page. The module overview help information is displayed by the Help
* module. It can be accessed from the page at /admin/help or from the Extend
* page. If a module implements hook_help() the help system expects module
* overview help to be provided.
*
* For detailed usage examples of:
* - Module overview help, see content_translation_help(). Module overview
* help should follow
* @link https://www.drupal.org/node/632280 the standard help template. @endlink
* - Page-specific help using only routes, see book_help().
* - Page-specific help using routes and $request, see block_help().
*
* @param string $route_name
* For page-specific help, use the route name as identified in the
* module's routing.yml file. For module overview help, the route name
* will be in the form of "help.page.$modulename".
* @param Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match. This can be used to generate different help
* output for different pages that share the same route.
*
* @return string|array
* A render array, localized string, or object that can be rendered into
* a string, containing the help text.
*/
function hook_help($route_name, \Drupal\Core\Routing\RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the block module.
case 'help.page.block':
return '<p>' . t('Blocks are boxes of content rendered into an area, or region, of a web page. The default theme Bartik, for example, implements the regions "Sidebar first", "Sidebar second", "Featured", "Content", "Header", "Footer", etc., and a block may appear in any one of these areas. The <a href=":blocks">blocks administration page</a> provides a drag-and-drop interface for assigning a block to a region, and for controlling the order of blocks within regions.', array(':blocks' => \Drupal::url('block.admin_display'))) . '</p>';
// Help for another path in the block module.
case 'block.admin_display':
return '<p>' . t('This page provides a drag-and-drop interface for assigning a block to a region, and for controlling the order of blocks within regions. Since not all themes implement the same regions, or display regions in the same way, blocks are positioned on a per-theme basis. Remember that your changes will not be saved until you click the <em>Save blocks</em> button at the bottom of the page.') . '</p>';
}
}
/**
* Perform alterations on help page section plugin definitions.
*
* Sections for the page at /admin/help are provided by plugins. This hook
* allows modules to alter the plugin definitions.
*
* @param array $info
* Array of plugin information exposed by hook page section plugins, altered
* by reference.
*
* @see \Drupal\help\HelpSectionPluginInterface
* @see \Drupal\help\Annotation\HelpSection
* @see \Drupal\help\HelpSectionManager
*/
function hook_help_section_info_alter(&$info) {
// Alter the header for the module overviews section.
$info['hook_help']['header'] = t('Overviews of modules');
}
/**
* @} End of "addtogroup hooks".
*/

View file

@ -0,0 +1,6 @@
name: Help
type: module
description: 'Manages the display of online help.'
package: Core
version: VERSION
core: 8.x

View file

@ -0,0 +1,6 @@
help.main:
title: Help
description: 'Reference for usage, configuration, and modules.'
route_name: help.main
weight: 9
parent: system.admin

View file

@ -0,0 +1,78 @@
<?php
/**
* @file
* Manages displaying online help.
*/
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function help_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.main':
$output = '<h2>' . t('Getting Started') . '</h2>';
$output .= '<p>' . t('Follow these steps to set up and start using your website:') . '</p>';
$output .= '<ol>';
$output .= '<li>' . t('<strong>Configure your website</strong> Once logged in, visit the <a href=":admin">Administration page</a>, where you may <a href=":config">customize and configure</a> all aspects of your website.', array(':admin' => \Drupal::url('system.admin'), ':config' => \Drupal::url('system.admin_config'))) . '</li>';
$output .= '<li>' . t('<strong>Enable additional functionality</strong> Next, visit the <a href=":modules">Extend page</a> and enable modules that suit your specific needs. You can find additional modules at the <a href=":download_modules">Drupal.org modules page</a>.', array(':modules' => \Drupal::url('system.modules_list'), ':download_modules' => 'https://www.drupal.org/project/modules')) . '</li>';
$output .= '<li>' . t('<strong>Customize your website design</strong> To change the "look and feel" of your website, visit the <a href=":themes">Appearance page</a>. You may choose from one of the included themes or download additional themes from the <a href=":download_themes">Drupal.org themes page</a>.', array(':themes' => \Drupal::url('system.themes_page'), ':download_themes' => 'https://www.drupal.org/project/themes')) . '</li>';
// Display a link to the create content page if Node module is enabled.
if (\Drupal::moduleHandler()->moduleExists('node')) {
$output .= '<li>' . t('<strong>Start posting content</strong> Finally, you may <a href=":content">add new content</a> to your website.', array(':content' => \Drupal::url('node.add_page'))) . '</li>';
}
$output .= '</ol>';
$output .= '<p>' . t('For more information, refer to the help listed on this page or to the <a href=":docs">online documentation</a> and <a href=":support">support</a> pages at <a href=":drupal">drupal.org</a>.', array(':docs' => 'https://www.drupal.org/documentation', ':support' => 'https://www.drupal.org/support', ':drupal' => 'https://www.drupal.org')) . '</p>';
return ['#markup' => $output];
case 'help.page.help':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Help module generates <a href=":help-page">Help reference pages</a> to guide you through the use and configuration of modules, and provides a Help block with page-level help. The reference pages are a starting point for <a href=":handbook">Drupal.org online documentation</a> pages that contain more extensive and up-to-date information, are annotated with user-contributed comments, and serve as the definitive reference point for all Drupal documentation. For more information, see the <a href=":help">online documentation for the Help module</a>.', array(':help' => 'https://www.drupal.org/documentation/modules/help/', ':handbook' => 'https://www.drupal.org/documentation', ':help-page' => \Drupal::url('help.main'))) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Providing a help reference') . '</dt>';
$output .= '<dd>' . t('The Help module displays explanations for using each module listed on the main <a href=":help">Help reference page</a>.', array(':help' => \Drupal::url('help.main'))) . '</dd>';
$output .= '<dt>' . t('Providing page-specific help') . '</dt>';
$output .= '<dd>' . t('Page-specific help text provided by modules is displayed in the Help block. This block can be placed and configured on the <a href=":blocks">Block layout page</a>.', array(':blocks' => (\Drupal::moduleHandler()->moduleExists('block')) ? \Drupal::url('block.admin_display') : '#')) . '</dd>';
$output .= '</dl>';
return ['#markup' => $output];
}
}
/**
* Implements hook_theme().
*/
function help_theme($existing, $type, $theme, $path) {
return [
'help_section' => [
'variables' => [
'title' => NULL,
'description' => NULL,
'links' => NULL,
'empty' => NULL,
],
],
];
}
/**
* Implements hook_preprocess_HOOK() for block templates.
*/
function help_preprocess_block(&$variables) {
if ($variables['plugin_id'] == 'help_block') {
$variables['attributes']['role'] = 'complementary';
}
}
/**
* Implements hook_block_view_BASE_BLOCK_ID_alter().
*/
function help_block_view_help_block_alter(array &$build, BlockPluginInterface $block) {
// Assume that most users do not need or want to perform contextual actions on
// the help block, so don't needlessly draw attention to it.
unset($build['#contextual_links']);
}

View file

@ -0,0 +1,15 @@
help.main:
path: '/admin/help'
defaults:
_controller: '\Drupal\help\Controller\HelpController::helpMain'
_title: 'Help'
requirements:
_permission: 'access administration pages'
help.page:
path: '/admin/help/{name}'
defaults:
_controller: '\Drupal\help\Controller\HelpController::helpPage'
_title: 'Help'
requirements:
_permission: 'access administration pages'

View file

@ -0,0 +1,4 @@
services:
plugin.manager.help_section:
class: Drupal\help\HelpSectionManager
parent: default_plugin_manager

View file

@ -0,0 +1,60 @@
<?php
namespace Drupal\help\Annotation;
use Drupal\Component\Annotation\Plugin;
/**
* Defines a Plugin annotation object for help page section plugins.
*
* Plugin Namespace: Plugin\HelpSection
*
* For a working example, see \Drupal\help\Plugin\HelpSection\HookHelpSection.
*
* @see \Drupal\help\HelpSectionPluginInterface
* @see \Drupal\help\Plugin\HelpSection\HelpSectionPluginBase
* @see \Drupal\help\HelpSectionManager
* @see hook_help_section_info_alter()
* @see plugin_api
*
* @Annotation
*/
class HelpSection extends Plugin {
/**
* The plugin ID.
*
* @var string
*/
public $id;
/**
* The text to use as the title of the help page section.
*
* @var \Drupal\Core\Annotation\Translation
*
* @ingroup plugin_translatable
*/
public $title;
/**
* The description of the help page section.
*
* @var \Drupal\Core\Annotation\Translation
*
* @ingroup plugin_translatable
*/
public $description;
/**
* The (optional) permission needed to view the help section.
*
* Only set if this section needs its own permission, beyond the generic
* 'access administration pages' permission needed to see the /admin/help
* page itself.
*
* @var string
*/
public $permission = '';
}

View file

@ -0,0 +1,162 @@
<?php
namespace Drupal\help\Controller;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\help\HelpSectionManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Controller routines for help routes.
*/
class HelpController extends ControllerBase {
/**
* The current route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/**
* The help section plugin manager.
*
* @var \Drupal\help\HelpSectionManager
*/
protected $helpManager;
/**
* Creates a new HelpController.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
* @param \Drupal\help\HelpSectionManager $help_manager
* The help section manager.
*/
public function __construct(RouteMatchInterface $route_match, HelpSectionManager $help_manager) {
$this->routeMatch = $route_match;
$this->helpManager = $help_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('current_route_match'),
$container->get('plugin.manager.help_section')
);
}
/**
* Prints a page listing various types of help.
*
* The page has sections defined by \Drupal\help\HelpSectionPluginInterface
* plugins.
*
* @return array
* A render array for the help page.
*/
public function helpMain() {
$output = [];
// We are checking permissions, so add the user.permissions cache context.
$cacheability = new CacheableMetadata();
$cacheability->addCacheContexts(['user.permissions']);
$plugins = $this->helpManager->getDefinitions();
$cacheability->addCacheableDependency($this->helpManager);
foreach ($plugins as $plugin_id => $plugin_definition) {
// Check the provided permission.
if (!empty($plugin_definition['permission']) && !$this->currentuser()->hasPermission($plugin_definition['permission'])) {
continue;
}
// Add the section to the page.
/** @var \Drupal\help\HelpSectionPluginInterface $plugin */
$plugin = $this->helpManager->createInstance($plugin_id);
$this_output = [
'#theme' => 'help_section',
'#title' => $plugin->getTitle(),
'#description' => $plugin->getDescription(),
'#empty' => $this->t('There is currently nothing in this section.'),
'#links' => [],
];
$links = $plugin->listTopics();
if (is_array($links) && count($links)) {
$this_output['#links'] = $links;
}
$cacheability->addCacheableDependency($plugin);
$output[$plugin_id] = $this_output;
}
$cacheability->applyTo($output);
return $output;
}
/**
* Prints a page listing general help for a module.
*
* @param string $name
* A module name to display a help page for.
*
* @return array
* A render array as expected by drupal_render().
*
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function helpPage($name) {
$build = array();
if ($this->moduleHandler()->implementsHook($name, 'help')) {
$module_name = $this->moduleHandler()->getName($name);
$build['#title'] = $module_name;
$info = system_get_info('module', $name);
if ($info['package'] === 'Core (Experimental)') {
drupal_set_message($this->t('This module is experimental. <a href=":url">Experimental modules</a> are provided for testing purposes only. Use at your own risk.', [':url' => 'https://www.drupal.org/core/experimental']), 'warning');
}
$temp = $this->moduleHandler()->invoke($name, 'help', array("help.page.$name", $this->routeMatch));
if (empty($temp)) {
$build['top'] = ['#markup' => $this->t('No help is available for module %module.', array('%module' => $module_name))];
}
else {
if (!is_array($temp)) {
$temp = ['#markup' => $temp];
}
$build['top'] = $temp;
}
// Only print list of administration pages if the module in question has
// any such pages associated with it.
$admin_tasks = system_get_module_admin_tasks($name, system_get_info('module', $name));
if (!empty($admin_tasks)) {
$links = array();
foreach ($admin_tasks as $task) {
$link['url'] = $task['url'];
$link['title'] = $task['title'];
$links[] = $link;
}
$build['links'] = array(
'#theme' => 'links__help',
'#heading' => array(
'level' => 'h3',
'text' => $this->t('@module administration pages', array('@module' => $module_name)),
),
'#links' => $links,
);
}
return $build;
}
else {
throw new NotFoundHttpException();
}
}
}

View file

@ -0,0 +1,37 @@
<?php
namespace Drupal\help;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
/**
* Manages help page section plugins.
*
* @see \Drupal\help\HelpSectionPluginInterface
* @see \Drupal\help\Plugin\HelpSection\HelpSectionPluginBase
* @see \Drupal\help\Annotation\HelpSection
* @see hook_help_section_info_alter()
*/
class HelpSectionManager extends DefaultPluginManager {
/**
* Constructs a new HelpSectionManager.
*
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
* keyed by the corresponding namespace to look for plugin implementations.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* Cache backend instance to use.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler for the alter hook.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/HelpSection', $namespaces, $module_handler, 'Drupal\help\HelpSectionPluginInterface', 'Drupal\help\Annotation\HelpSection');
$this->alterInfo('help_section_info');
$this->setCacheBackend($cache_backend, 'help_section_plugins');
}
}

View file

@ -0,0 +1,49 @@
<?php
namespace Drupal\help;
use Drupal\Component\Plugin\PluginInspectionInterface;
use Drupal\Core\Cache\CacheableDependencyInterface;
/**
* Provides an interface for a plugin for a section of the /admin/help page.
*
* Plugins of this type need to be annotated with
* \Drupal\help\Annotation\HelpSection annotation, and placed in the
* Plugin\HelpSection namespace directory. They are managed by the
* \Drupal\help\HelpSectionManager plugin manager class. There is a base
* class that may be helpful:
* \Drupal\help\Plugin\HelpSection\HelpSectionPluginBase.
*/
interface HelpSectionPluginInterface extends PluginInspectionInterface, CacheableDependencyInterface {
/**
* Returns the title of the help section.
*
* @return string
* The title text, which could be a plain string or an object that can be
* cast to a string.
*/
public function getTitle();
/**
* Returns the description text for the help section.
*
* @return string
* The description text, which could be a plain string or an object that
* can be cast to a string.
*/
public function getDescription();
/**
* Returns a list of topics to show in the help section.
*
* @return array
* A sorted list of topic links or render arrays for topic links. The links
* will be shown in the help section; if the returned array of links is
* empty, the section will be shown with some generic empty text.
*/
public function listTopics();
}

View file

@ -0,0 +1,115 @@
<?php
namespace Drupal\help\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Provides a 'Help' block.
*
* @Block(
* id = "help_block",
* admin_label = @Translation("Help")
* )
*/
class HelpBlock extends BlockBase implements ContainerFactoryPluginInterface {
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The current request.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;
/**
* The current route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/**
* Creates a HelpBlock instance.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, Request $request, ModuleHandlerInterface $module_handler, RouteMatchInterface $route_match) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->request = $request;
$this->moduleHandler = $module_handler;
$this->routeMatch = $route_match;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('request_stack')->getCurrentRequest(),
$container->get('module_handler'),
$container->get('current_route_match')
);
}
/**
* {@inheritdoc}
*/
public function build() {
// Do not show on a 403 or 404 page.
if ($this->request->attributes->has('exception')) {
return [];
}
$implementations = $this->moduleHandler->getImplementations('help');
$build = [];
$args = [
$this->routeMatch->getRouteName(),
$this->routeMatch,
];
foreach ($implementations as $module) {
// Don't add empty strings to $build array.
if ($help = $this->moduleHandler->invoke($module, 'help', $args)) {
// Convert strings to #markup render arrays so that they will XSS admin
// filtered.
$build[] = is_array($help) ? $help : ['#markup' => $help];
}
}
return $build;
}
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
return Cache::mergeContexts(parent::getCacheContexts(), ['route']);
}
}

View file

@ -0,0 +1,34 @@
<?php
namespace Drupal\help\Plugin\HelpSection;
use Drupal\Core\Cache\UnchangingCacheableDependencyTrait;
use Drupal\Core\Plugin\PluginBase;
use Drupal\help\HelpSectionPluginInterface;
/**
* Provides a base class for help section plugins.
*
* @see \Drupal\help\HelpSectionPluginInterface
* @see \Drupal\help\Annotation\HelpSection
* @see \Drupal\help\HelpSectionManager
*/
abstract class HelpSectionPluginBase extends PluginBase implements HelpSectionPluginInterface {
use UnchangingCacheableDependencyTrait;
/**
* {@inheritdoc}
*/
public function getTitle() {
return $this->getPluginDefinition()['title'];
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this->getPluginDefinition()['description'];
}
}

View file

@ -0,0 +1,72 @@
<?php
namespace Drupal\help\Plugin\HelpSection;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Link;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides the module topics list section for the help page.
*
* @HelpSection(
* id = "hook_help",
* title = @Translation("Module overviews"),
* description = @Translation("Module overviews are provided by modules. Overviews available for your installed modules:"),
* )
*/
class HookHelpSection extends HelpSectionPluginBase implements ContainerFactoryPluginInterface {
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Constructs a HookHelpSection object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ModuleHandlerInterface $module_handler) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->moduleHandler = $module_handler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('module_handler')
);
}
/**
* {@inheritdoc}
*/
public function listTopics() {
$topics = [];
foreach ($this->moduleHandler->getImplementations('help') as $module) {
$title = $this->moduleHandler->getName($module);
$topics[$title] = Link::createFromRoute($title, 'help.page', ['name' => $module]);
}
// Sort topics by title, which is the array key above.
ksort($topics);
return $topics;
}
}

View file

@ -0,0 +1,25 @@
{#
/**
* @file
* Default theme implementation for a section of the help page.
*
* Available variables:
* - title: The section title.
* - description: The description text for the section.
* - links: Links to display in the section.
* - empty: Text to display if there are no links.
*
* @ingroup themeable
*/
#}
<h2>{{ title }}</h2>
<p>{{ description }}</p>
{% if links %}
<ul>
{% for link in links %}
<li>{{ link }}</li>
{% endfor %}
</ul>
{% else %}
<p>{{ empty }}</p>
{% endif %}

View file

@ -0,0 +1,7 @@
name: 'Help Page Test'
type: module
description: 'Module to test the help page.'
package: Testing
version: VERSION
core: 8.x
hidden: true

View file

@ -0,0 +1,29 @@
<?php
/**
* @file
* Help Page Test module to test the help page.
*/
use \Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function help_page_test_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.help_page_test':
// Make the help text conform to core standards. See
// \Drupal\system\Tests\Module\InstallUninstallTest::assertHelp().
return t('Read the <a href=":url">online documentation for the Help Page Test module</a>.', [':url' => 'http://www.example.com']);
case 'help_page_test.has_help':
return t('I have help!');
case 'help_page_test.test_array':
return ['#markup' => 'Help text from help_page_test_help module.'];
}
// Ensure that hook_help() can return an empty string and not cause the block
// to display.
return '';
}

View file

@ -0,0 +1,20 @@
help_page_test.has_help:
path: '/help_page_test/has_help'
defaults:
_controller: '\Drupal\help_page_test\HelpPageTestController::hasHelp'
requirements:
_access: 'TRUE'
help_page_test.no_help:
path: '/help_page_test/no_help'
defaults:
_controller: '\Drupal\help_page_test\HelpPageTestController::noHelp'
requirements:
_access: 'TRUE'
help_page_test.test_array:
path: '/help_page_test/test_array'
defaults:
_controller: '\Drupal\help_page_test\HelpPageTestController::testArray'
requirements:
_access: 'TRUE'

View file

@ -0,0 +1,40 @@
<?php
namespace Drupal\help_page_test;
/**
* Provides controllers for testing the help block.
*/
class HelpPageTestController {
/**
* Provides a route with help.
*
* @return array
* A render array.
*/
public function hasHelp() {
return ['#markup' => 'A route with help.'];
}
/**
* Provides a route with no help.
*
* @return array
* A render array.
*/
public function noHelp() {
return ['#markup' => 'A route without help.'];
}
/**
* Provides a route which has multiple array returns from hook_help().
*
* @return array
* A render array.
*/
public function testArray() {
return ['#markup' => 'A route which has multiple array returns from hook_help().'];
}
}

View file

@ -0,0 +1,24 @@
<?php
namespace Drupal\help_page_test\Plugin\HelpSection;
use Drupal\help\Plugin\HelpSection\HelpSectionPluginBase;
/**
* Provides an empty section for the help page, for testing.
*
* @HelpSection(
* id = "empty_section",
* title = @Translation("Empty section"),
* description = @Translation("This description should appear."),
* )
*/
class EmptyHelpSection extends HelpSectionPluginBase {
/**
* {@inheritdoc}
*/
public function listTopics() {
return [];
}
}

View file

@ -0,0 +1,6 @@
name: help_test
type: module
core: 8.x
package: Testing
dependencies:
- help

View file

@ -0,0 +1,16 @@
<?php
/**
* @file
* Test Help module.
*/
use \Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function help_test_help($route_name, RouteMatchInterface $route_match) {
// Do not implement a module overview page to test an empty implementation.
// @see \Drupal\help\Tests\HelpTest
}

View file

@ -0,0 +1,62 @@
<?php
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 getPathFromRoute($name, $parameters = array()) {
throw new \Exception();
}
/**
* {@inheritdoc}
*/
public function generateFromRoute($name, $parameters = array(), $options = array(), $collect_bubbleable_metadata = FALSE) {
throw new \Exception();
}
/**
* {@inheritdoc}
*/
public function supports($name) {
throw new \Exception();
}
/**
* {@inheritdoc}
*/
public function getRouteDebugMessage($name, array $parameters = array()) {
throw new \Exception();
}
}

View file

@ -0,0 +1,7 @@
name: 'More Help Page Test'
type: module
description: 'Module to test the help page.'
package: Testing
version: VERSION
core: 8.x
hidden: true

View file

@ -0,0 +1,20 @@
<?php
/**
* @file
* More Help Page Test module to test the help blocks.
*/
use \Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function more_help_page_test_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Return help for the same route as the help_page_test module.
case 'help_page_test.test_array':
return ['#markup' => 'Help text from more_help_page_test_help module.'];
}
}

View file

@ -0,0 +1,56 @@
<?php
namespace Drupal\Tests\help\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Verifies help for experimental modules.
*
* @group help
*/
class ExperimentalHelpTest extends BrowserTestBase {
/**
* Modules to enable.
*
* The experimental_module_test module implements hook_help() and is in the
* Core (Experimental) package.
*
* @var array
*/
public static $modules = array('help', 'experimental_module_test', 'help_page_test');
/**
* The admin user.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* {@inheritoc}
*/
protected function setUp() {
parent::setUp();
$this->adminUser = $this->drupalCreateUser(['access administration pages']);
}
/**
* Verifies that a warning message is displayed for experimental modules.
*/
public function testExperimentalHelp() {
$this->drupalLogin($this->adminUser);
$this->drupalGet('admin/help/experimental_module_test');
$this->assertText('This module is experimental.');
// Regular modules should not display the message.
$this->drupalGet('admin/help/help_page_test');
$this->assertNoText('This module is experimental.');
// Ensure the actual help page is displayed to avoid a false positive.
$this->assertResponse(200);
$this->assertText('online documentation for the Help Page Test module');
}
}

View file

@ -0,0 +1,50 @@
<?php
namespace Drupal\Tests\help\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Tests display of help block.
*
* @group help
*/
class HelpBlockTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['help', 'help_page_test', 'block', 'more_help_page_test'];
/**
* The help block instance.
*
* @var \Drupal\block\Entity\Block
*/
protected $helpBlock;
protected function setUp() {
parent::setUp();
$this->helpBlock = $this->placeBlock('help_block');
}
/**
* Logs in users, tests help pages.
*/
public function testHelp() {
$this->drupalGet('help_page_test/has_help');
$this->assertText(t('I have help!'));
$this->assertText($this->helpBlock->label());
$this->drupalGet('help_page_test/no_help');
// The help block should not appear when there is no help.
$this->assertNoText($this->helpBlock->label());
// Ensure that if two hook_help() implementations both return a render array
// the output is as expected.
$this->drupalGet('help_page_test/test_array');
$this->assertText('Help text from more_help_page_test_help module.');
$this->assertText('Help text from help_page_test_help module.');
}
}

View file

@ -0,0 +1,160 @@
<?php
namespace Drupal\Tests\help\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Verify help display and user access to help based on permissions.
*
* @group help
*/
class HelpTest extends BrowserTestBase {
/**
* Modules to enable.
*
* The help_test module implements hook_help() but does not provide a module
* overview page. The help_page_test module has a page section plugin that
* returns no links.
*
* @var array.
*/
public static $modules = array('help_test', 'help_page_test');
/**
* Use the Standard profile to test help implementations of many core modules.
*/
protected $profile = 'standard';
/**
* The admin user that will be created.
*/
protected $adminUser;
/**
* The anonymous user that will be created.
*/
protected $anyUser;
protected function setUp() {
parent::setUp();
// Create users.
$this->adminUser = $this->drupalCreateUser(array('access administration pages', 'view the administration theme', 'administer permissions'));
$this->anyUser = $this->drupalCreateUser(array());
}
/**
* Logs in users, tests help pages.
*/
public function testHelp() {
// Log in the root user to ensure as many admin links appear as possible on
// the module overview pages.
$this->drupalLogin($this->rootUser);
$this->verifyHelp();
// Log in the regular user.
$this->drupalLogin($this->anyUser);
$this->verifyHelp(403);
// Verify that introductory help text exists, goes for 100% module coverage.
$this->drupalLogin($this->adminUser);
$this->drupalGet('admin/help');
$this->assertRaw(t('For more information, refer to the help listed on this page or to the <a href=":docs">online documentation</a> and <a href=":support">support</a> pages at <a href=":drupal">drupal.org</a>.', array(':docs' => 'https://www.drupal.org/documentation', ':support' => 'https://www.drupal.org/support', ':drupal' => 'https://www.drupal.org')));
// Verify that hook_help() section title and description appear.
$this->assertRaw('<h2>' . t('Module overviews') . '</h2>');
$this->assertRaw('<p>' . t('Module overviews are provided by modules. Overviews available for your installed modules:'), '</p>');
// Verify that an empty section is handled correctly.
$this->assertRaw('<h2>' . t('Empty section') . '</h2>');
$this->assertRaw('<p>' . t('This description should appear.'), '</p>');
$this->assertText(t('There is currently nothing in this section.'));
// Make sure links are properly added for modules implementing hook_help().
foreach ($this->getModuleList() as $module => $name) {
$this->assertLink($name, 0, format_string('Link properly added to @name (admin/help/@module)', array('@module' => $module, '@name' => $name)));
}
// Ensure that module which does not provide an module overview page is
// handled correctly.
$this->clickLink(\Drupal::moduleHandler()->getName('help_test'));
$this->assertRaw(t('No help is available for module %module.', array('%module' => \Drupal::moduleHandler()->getName('help_test'))));
// Verify that the order of topics is alphabetical by displayed module
// name, by checking the order of some modules, including some that would
// have a different order if it was done by machine name instead.
$this->drupalGet('admin/help');
$page_text = $this->getTextContent();
$start = strpos($page_text, 'Module overviews');
$pos = $start;
$list = ['Block', 'Color', 'Custom Block', 'History', 'Text Editor'];
foreach ($list as $name) {
$this->assertLink($name);
$new_pos = strpos($page_text, $name, $start);
$this->assertTrue($new_pos > $pos, 'Order of ' . $name . ' is correct on page');
$pos = $new_pos;
}
}
/**
* Verifies the logged in user has access to the various help pages.
*
* @param int $response
* (optional) An HTTP response code. Defaults to 200.
*/
protected function verifyHelp($response = 200) {
$this->drupalGet('admin/index');
$this->assertResponse($response);
if ($response == 200) {
$this->assertText('This page shows you all available administration tasks for each module.');
}
else {
$this->assertNoText('This page shows you all available administration tasks for each module.');
}
foreach ($this->getModuleList() as $module => $name) {
// View module help page.
$this->drupalGet('admin/help/' . $module);
$this->assertResponse($response);
if ($response == 200) {
$this->assertTitle($name . ' | Drupal', format_string('%module title was displayed', array('%module' => $module)));
$this->assertEquals($name, $this->cssSelect('h1.page-title')[0]->getText(), "$module heading was displayed");
$admin_tasks = system_get_module_admin_tasks($module, system_get_info('module', $module));
if (!empty($admin_tasks)) {
$this->assertText(t('@module administration pages', array('@module' => $name)));
}
foreach ($admin_tasks as $task) {
$this->assertLink($task['title']);
// Ensure there are no double escaped '&' or '<' characters.
$this->assertNoEscaped('&amp;', 'The help text does not have double escaped &amp;.');
$this->assertNoEscaped('&lt;', 'The help text does not have double escaped &lt;.');
// Ensure there are no escaped '<' characters.
$this->assertNoEscaped('<', 'The help text does not have single escaped &lt;.');
}
// Ensure there are no double escaped '&' or '<' characters.
$this->assertNoEscaped('&amp;');
$this->assertNoEscaped('&lt;');
// Ensure there are no escaped '<' characters.
$this->assertNoEscaped('<');
}
}
}
/**
* Gets the list of enabled modules that implement hook_help().
*
* @return array
* A list of enabled modules.
*/
protected function getModuleList() {
$modules = array();
$module_data = system_rebuild_module_data();
foreach (\Drupal::moduleHandler()->getImplementations('help') as $module) {
$modules[$module] = $module_data[$module]->info['name'];
}
return $modules;
}
}

View file

@ -0,0 +1,49 @@
<?php
namespace Drupal\Tests\help\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Verify no help is displayed for modules not providing any help.
*
* @group help
*/
class NoHelpTest extends BrowserTestBase {
/**
* Modules to enable.
*
* Use one of the test modules that do not implement hook_help().
*
* @var array.
*/
public static $modules = array('help', 'menu_test');
/**
* The user who will be created.
*/
protected $adminUser;
protected function setUp() {
parent::setUp();
$this->adminUser = $this->drupalCreateUser(array('access administration pages'));
}
/**
* Ensures modules not implementing help do not appear on admin/help.
*/
public function testMainPageNoHelp() {
$this->drupalLogin($this->adminUser);
$this->drupalGet('admin/help');
$this->assertResponse(200);
$this->assertText('Module overviews are provided by modules');
$this->assertFalse(\Drupal::moduleHandler()->implementsHook('menu_test', 'help'), 'The menu_test module does not implement hook_help');
$this->assertNoText(\Drupal::moduleHandler()->getName('menu_test'), 'Making sure the test module menu_test does not display a help link on admin/help.');
$this->drupalGet('admin/help/menu_test');
$this->assertResponse(404, 'Getting a module overview help page for a module that does not implement hook_help() results in a 404.');
}
}

View file

@ -0,0 +1,52 @@
<?php
namespace Drupal\Tests\help\Kernel;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Routing\RouteMatch;
use Drupal\help_test\SupernovaGenerator;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests the empty HTML page.
*
* @group help
*/
class HelpEmptyPageTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['system', 'help_test', 'user'];
/**
* {@inheritdoc}
*/
public function register(ContainerBuilder $container) {
parent::register($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;
});
$this->enableModules(array_keys($all_modules));
$this->installEntitySchema('menu_link_content');
$route = \Drupal::service('router.route_provider')->getRouteByName('<front>');
\Drupal::service('module_handler')->invokeAll('help', ['<front>', new RouteMatch('<front>', $route)]);
}
}