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,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;
}
}