Move into nested docroot
This commit is contained in:
parent
83a0d3a149
commit
c8b70abde9
13405 changed files with 0 additions and 0 deletions
115
web/core/modules/help/src/Plugin/Block/HelpBlock.php
Normal file
115
web/core/modules/help/src/Plugin/Block/HelpBlock.php
Normal 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']);
|
||||
}
|
||||
|
||||
}
|
|
@ -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'];
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue