Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176
This commit is contained in:
commit
9921556621
13277 changed files with 1459781 additions and 0 deletions
60
core/modules/help/help.api.php
Normal file
60
core/modules/help/help.api.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?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
|
||||
* 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
|
||||
* A localized 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>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "addtogroup hooks".
|
||||
*/
|
6
core/modules/help/help.info.yml
Normal file
6
core/modules/help/help.info.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
name: Help
|
||||
type: module
|
||||
description: 'Manages the display of online help.'
|
||||
package: Core
|
||||
version: VERSION
|
||||
core: 8.x
|
6
core/modules/help/help.links.menu.yml
Normal file
6
core/modules/help/help.links.menu.yml
Normal 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
|
62
core/modules/help/help.module
Normal file
62
core/modules/help/help.module
Normal file
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Manages displaying online help.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Block\BlockPluginInterface;
|
||||
|
||||
/**
|
||||
* 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 subjects listed in the Help Topics section 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 $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 $output;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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']);
|
||||
}
|
15
core/modules/help/help.routing.yml
Normal file
15
core/modules/help/help.routing.yml
Normal 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'
|
154
core/modules/help/src/Controller/HelpController.php
Normal file
154
core/modules/help/src/Controller/HelpController.php
Normal file
|
@ -0,0 +1,154 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\help\Controller\HelpController.
|
||||
*/
|
||||
|
||||
namespace Drupal\help\Controller;
|
||||
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
|
||||
/**
|
||||
* Controller routines for help routes.
|
||||
*/
|
||||
class HelpController extends ControllerBase {
|
||||
|
||||
/**
|
||||
* The current route match.
|
||||
*
|
||||
* @var \Drupal\Core\Routing\RouteMatchInterface
|
||||
*/
|
||||
protected $routeMatch;
|
||||
|
||||
/**
|
||||
* Creates a new HelpController.
|
||||
*
|
||||
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
|
||||
* The current route match.
|
||||
*/
|
||||
public function __construct(RouteMatchInterface $route_match) {
|
||||
$this->routeMatch = $route_match;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('current_route_match')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a page listing a glossary of Drupal terminology.
|
||||
*
|
||||
* @return string
|
||||
* An HTML string representing the contents of help page.
|
||||
*/
|
||||
public function helpMain() {
|
||||
$output = array(
|
||||
'#markup' => '<h2>' . $this->t('Help topics') . '</h2><p>' . $this->t('Help is available on the following items:') . '</p>',
|
||||
'links' => $this->helpLinksAsList(),
|
||||
);
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a formatted list of available help topics.
|
||||
*
|
||||
* @return string
|
||||
* A string containing the formatted list.
|
||||
*/
|
||||
protected function helpLinksAsList() {
|
||||
$modules = array();
|
||||
foreach ($this->moduleHandler()->getImplementations('help') as $module) {
|
||||
$modules[$module] = $this->moduleHandler->getName($module);
|
||||
}
|
||||
asort($modules);
|
||||
|
||||
// Output pretty four-column list.
|
||||
$count = count($modules);
|
||||
$break = ceil($count / 4);
|
||||
$column = array(
|
||||
'#type' => 'container',
|
||||
'links' => array('#theme' => 'item_list'),
|
||||
'#attributes' => array('class' => array('layout-column', 'quarter')),
|
||||
);
|
||||
$output = array(
|
||||
'#prefix' => '<div class="clearfix">',
|
||||
'#suffix' => '</div>',
|
||||
0 => $column,
|
||||
);
|
||||
|
||||
$i = 0;
|
||||
$current_column = 0;
|
||||
foreach ($modules as $module => $name) {
|
||||
$output[$current_column]['links']['#items'][] = $this->l($name, new Url('help.page', array('name' => $module)));
|
||||
if (($i + 1) % $break == 0 && ($i + 1) != $count) {
|
||||
$current_column++;
|
||||
$output[$current_column] = $column;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
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'] = SafeMarkup::checkPlain($module_name);
|
||||
|
||||
$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 {
|
||||
$build['top']['#markup'] = $temp;
|
||||
}
|
||||
|
||||
// Only print list of administration pages if the module in question has
|
||||
// any such pages associated to 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
142
core/modules/help/src/Plugin/Block/HelpBlock.php
Normal file
142
core/modules/help/src/Plugin/Block/HelpBlock.php
Normal file
|
@ -0,0 +1,142 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\help\Plugin\Block\HelpBlock.
|
||||
*/
|
||||
|
||||
namespace Drupal\help\Plugin\Block;
|
||||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Block\BlockBase;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
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 {
|
||||
|
||||
/**
|
||||
* Stores the help text associated with the active menu item.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $help;
|
||||
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
protected function blockAccess(AccountInterface $account) {
|
||||
$this->help = $this->getActiveHelp($this->request);
|
||||
if ($this->help) {
|
||||
return AccessResult::allowed();
|
||||
}
|
||||
else {
|
||||
return AccessResult::forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the help associated with the active menu item.
|
||||
*
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
* The current request.
|
||||
*/
|
||||
protected function getActiveHelp(Request $request) {
|
||||
// Do not show on a 403 or 404 page.
|
||||
if ($request->attributes->has('exception')) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$help = $this->moduleHandler->invokeAll('help', array($this->routeMatch->getRouteName(), $this->routeMatch));
|
||||
return $help ? implode("\n", $help) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build() {
|
||||
return array(
|
||||
'#children' => $this->help,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCacheContexts() {
|
||||
// The "Help" block must be cached per URL: help is defined for a
|
||||
// given path, and does not come with any access restrictions.
|
||||
return array('url');
|
||||
}
|
||||
|
||||
}
|
65
core/modules/help/src/Tests/HelpEmptyPageTest.php
Normal file
65
core/modules/help/src/Tests/HelpEmptyPageTest.php
Normal file
|
@ -0,0 +1,65 @@
|
|||
<?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)]);
|
||||
}
|
||||
|
||||
}
|
134
core/modules/help/src/Tests/HelpTest.php
Normal file
134
core/modules/help/src/Tests/HelpTest.php
Normal file
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\help\Tests\HelpTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\help\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Verify help display and user access to help based on permissions.
|
||||
*
|
||||
* @group help
|
||||
*/
|
||||
class HelpTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* The help_test module implements hook_help() but does not provide a module
|
||||
* overview page.
|
||||
*
|
||||
* @var array.
|
||||
*/
|
||||
public static $modules = array('help_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();
|
||||
|
||||
$this->getModuleList();
|
||||
|
||||
// Create users.
|
||||
$this->adminUser = $this->drupalCreateUser(array('access administration pages', 'view the administration theme', 'administer permissions'));
|
||||
$this->anyUser = $this->drupalCreateUser(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs in users, creates dblog events, and tests dblog functionality.
|
||||
*/
|
||||
public function testHelp() {
|
||||
// Login the root user to ensure as many admin links appear as possible on
|
||||
// the module overview pages.
|
||||
$this->drupalLogin($this->rootUser);
|
||||
$this->verifyHelp();
|
||||
|
||||
// Login 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 subjects listed in the Help Topics section 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')), 'Help intro text correctly appears.');
|
||||
|
||||
// Verify that help topics text appears.
|
||||
$this->assertRaw('<h2>' . t('Help topics') . '</h2><p>' . t('Help is available on the following items:') . '</p>', 'Help topics text correctly appears.');
|
||||
|
||||
// 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'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the logged in user has access to the various help nodes.
|
||||
*
|
||||
* @param integer $response
|
||||
* An HTTP response code.
|
||||
*/
|
||||
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 node.
|
||||
$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->assertRaw('<h1 class="page-title">' . t($name) . '</h1>', format_string('%module heading was displayed', array('%module' => $module)));
|
||||
$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']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
53
core/modules/help/src/Tests/NoHelpTest.php
Normal file
53
core/modules/help/src/Tests/NoHelpTest.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\help\Tests\NoHelpTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\help\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Verify no help is displayed for modules not providing any help.
|
||||
*
|
||||
* @group help
|
||||
*/
|
||||
class NoHelpTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* 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('Help is available on the following items', 'Help page is found.');
|
||||
$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.');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
name: help_test
|
||||
type: module
|
||||
core: 8.x
|
||||
package: Testing
|
||||
dependencies:
|
||||
- help
|
16
core/modules/help/tests/modules/help_test/help_test.module
Normal file
16
core/modules/help/tests/modules/help_test/help_test.module
Normal 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
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
<?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(), $collect_cacheability_metadata = FALSE) {
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPathFromRoute($name, $parameters = array()) {
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function generateFromRoute($name, $parameters = array(), $options = array(), $collect_cacheability_metadata = FALSE) {
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supports($name) {
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRouteDebugMessage($name, array $parameters = array()) {
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue