diff --git a/core/modules/help_topics/help_topics.module b/core/modules/help_topics/help_topics.module index 3990ad99c4..7ed6701e05 100644 --- a/core/modules/help_topics/help_topics.module +++ b/core/modules/help_topics/help_topics.module @@ -7,6 +7,7 @@ use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; +use Drupal\help_topics\Plugin\HelpTopic\HelpTopicTwig; /** * Implements hook_help(). @@ -39,7 +40,10 @@ function help_topics_help($route_name, RouteMatchInterface $route_match) { * Implements hook_theme(). */ function help_topics_theme($existing, $type, $theme, $path) { - return [ + $twigPlugins = array_keys(array_filter(\Drupal::service('plugin.manager.help_topic')->getDefinitions(), function (array $definition) { + return $definition['class'] === HelpTopicTwig::class; + })); + $return = [ 'help_topic' => [ 'variables' => [ 'body' => [], @@ -47,4 +51,10 @@ function help_topics_theme($existing, $type, $theme, $path) { ], ], ]; + foreach ($twigPlugins as $pluginId) { + $return[HelpTopicTwig::getThemeHook($pluginId)] = [ + 'variables' => [], + ]; + } + return $return; } diff --git a/core/modules/help_topics/help_topics/config_basic.help_topic.yml b/core/modules/help_topics/help_topics/config_basic.help_topic.yml index 6ae1debdb7..eb6504f765 100644 --- a/core/modules/help_topics/help_topics/config_basic.help_topic.yml +++ b/core/modules/help_topics/help_topics/config_basic.help_topic.yml @@ -3,33 +3,3 @@ label: 'Changing basic site settings' top_level: true related: { } list_on: { } -body: - - - text: 'The settings for your site are configured on various administrative pages, as follows:' - prefix_tags: '

' - suffix_tags: '

' - - - text: 'Site name, slogan, and email address' - prefix_tags: '
' - suffix_tags: '
' - - - text: 'On the Basic site settings page, which you can reach in the main Manage administrative menu, by navigating to Configuration > System > Basic site settings.' - prefix_tags: '
' - suffix_tags: '
' - - - text: 'Time zone and country' - prefix_tags: '
' - suffix_tags: '
' - - - text: 'On the Regional settings page, which you can reach in the main Manage administrative menu, by navigating to Configuration > Regional and language > Regional settings.' - prefix_tags: '
' - suffix_tags: '
' - - - text: 'Date and time formats' - prefix_tags: '
' - suffix_tags: '
' - - - text: 'On the Date and time formats page, which you can reach in the main Manage administrative menu, by navigating to Configuration > Regional and language > Date and time formats.' - prefix_tags: '
' - suffix_tags: '
' -body_format: help diff --git a/core/modules/help_topics/src/Controller/HelpTopicPluginController.php b/core/modules/help_topics/src/Controller/HelpTopicPluginController.php index c4285a2f25..2193dad4a1 100644 --- a/core/modules/help_topics/src/Controller/HelpTopicPluginController.php +++ b/core/modules/help_topics/src/Controller/HelpTopicPluginController.php @@ -9,6 +9,7 @@ use Drupal\Core\Render\RendererInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Utility\Token; +use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; /** * Controller for help topic plugins. @@ -76,36 +77,13 @@ public static function create(ContainerInterface $container) { public function viewHelpTopic($id) { $build = []; + if (!$this->helpTopicPluginManager->hasDefinition($id)) { + throw new AccessDeniedHttpException(); + } /* @var \Drupal\help_topics\Plugin\HelpTopic\HelpTopicPluginInterface $help_topic */ $help_topic = $this->helpTopicPluginManager->createInstance($id); - $body = $help_topic->getBody(); - - $matches = []; - // Find things that look like tokens, but using | instead of :, for - // example [foo|bar_baz|bang]. Allowable characters for the token pieces - // are letters, numbers, underscores, plus . and - characters. - if (preg_match_all('/\[([\w.\-]+\|)+[\w.\-]+\]/', $body, $matches)) { - // Replace the | with : in each token that was found. - $tokens = array_unique($matches[0]); - $replacements = []; - foreach ($tokens as $token) { - $replacements[] = str_replace('|', ':', $token); - } - // Replace all the tokens in the string. This could have all been done - // with one preg_replace instead of this whole if() statement, but the - // code would have been very difficult to read. - $body = str_replace($tokens, $replacements, $body); - } - - // Add in the body, with token replacement. - $bubbleable_metadata = new BubbleableMetadata(); - $build['#body'] = [ - '#type' => 'processed_text', - '#text' => $this->token->replace($body, [], [], $bubbleable_metadata), - '#format' => $help_topic->getBodyFormat(), - ]; - $bubbleable_metadata->applyTo($build['#body']); + $build['#body'] = $help_topic->getBody(); $this->renderer->addCacheableDependency($build, $help_topic); @@ -116,6 +94,9 @@ public function viewHelpTopic($id) { $related = $help_topic->getRelated(); foreach ($related as $other_id) { if ($other_id !== $help_topic->getPluginId()) { + if (!$this->helpTopicPluginManager->hasDefinition($other_id)) { + continue; + } /** @var \Drupal\help_topics\Plugin\HelpTopic\HelpTopicPluginInterface $topic */ $topic = $this->helpTopicPluginManager->createInstance($other_id); if ($topic) { diff --git a/core/modules/help_topics/src/Plugin/HelpTopic/HelpTopicPluginBase.php b/core/modules/help_topics/src/Plugin/HelpTopic/HelpTopicPluginBase.php index 72a231f0b7..b4cc3e2e32 100644 --- a/core/modules/help_topics/src/Plugin/HelpTopic/HelpTopicPluginBase.php +++ b/core/modules/help_topics/src/Plugin/HelpTopic/HelpTopicPluginBase.php @@ -34,20 +34,6 @@ public function getLabel() { return $this->pluginDefinition['label']; } - /** - * {@inheritdoc} - */ - public function getBody() { - return HtmlChunker::joinChunks($this->pluginDefinition['body']); - } - - /** - * {@inheritdoc} - */ - public function getBodyFormat() { - return $this->pluginDefinition['body_format']; - } - /** * {@inheritdoc} */ diff --git a/core/modules/help_topics/src/Plugin/HelpTopic/HelpTopicPluginInterface.php b/core/modules/help_topics/src/Plugin/HelpTopic/HelpTopicPluginInterface.php index 51f110bd18..619a8e4d60 100644 --- a/core/modules/help_topics/src/Plugin/HelpTopic/HelpTopicPluginInterface.php +++ b/core/modules/help_topics/src/Plugin/HelpTopic/HelpTopicPluginInterface.php @@ -27,14 +27,6 @@ public function getLabel(); */ public function getBody(); - /** - * Returns text format for the body of the topic. - * - * @return string - * The machine name of the text format for the topic body. - */ - public function getBodyFormat(); - /** * Returns whether this is a top-level topic or not. * diff --git a/core/modules/help_topics/src/Plugin/HelpTopic/HelpTopicPluginManager.php b/core/modules/help_topics/src/Plugin/HelpTopic/HelpTopicPluginManager.php index aaf873f981..2bea26dbae 100644 --- a/core/modules/help_topics/src/Plugin/HelpTopic/HelpTopicPluginManager.php +++ b/core/modules/help_topics/src/Plugin/HelpTopic/HelpTopicPluginManager.php @@ -38,7 +38,7 @@ class HelpTopicPluginManager extends DefaultPluginManager implements HelpTopicPl 'body' => [], // The machine name of the text format for the body in HTML form. 'body_format' => [], - 'class' => 'Drupal\help_topics\Plugin\HelpTopic\HelpTopicDefaultPlugin', + 'class' => HelpTopicTwig::class, 'cache_tag' => '', ]; diff --git a/core/modules/help_topics/src/Plugin/HelpTopic/HelpTopicDefaultPlugin.php b/core/modules/help_topics/src/Plugin/HelpTopic/HelpTopicTwig.php similarity index 81% rename from core/modules/help_topics/src/Plugin/HelpTopic/HelpTopicDefaultPlugin.php rename to core/modules/help_topics/src/Plugin/HelpTopic/HelpTopicTwig.php index 697197be79..66b6a1e454 100644 --- a/core/modules/help_topics/src/Plugin/HelpTopic/HelpTopicDefaultPlugin.php +++ b/core/modules/help_topics/src/Plugin/HelpTopic/HelpTopicTwig.php @@ -12,7 +12,7 @@ * The YAML files are stored in subdirectory help_topics, and must be named * id.help_topic.yaml, where id is the plugin ID. */ -class HelpTopicDefaultPlugin extends HelpTopicPluginBase implements ContainerFactoryPluginInterface { +class HelpTopicTwig extends HelpTopicPluginBase implements ContainerFactoryPluginInterface { /** * Constructs a HelpTopicDefaultPlugin. @@ -42,6 +42,8 @@ public function __construct(ContainerInterface $container, array $configuration, * The plugin ID. * @param array $plugin_definition * The plugin definition. + * + * @return $this */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { return new static($container, $configuration, $plugin_id, $plugin_definition); @@ -58,7 +60,22 @@ public function getLabel() { * {@inheritdoc} */ public function getBody() { - return new TranslatableMarkup(parent::getBody()); + return [ + '#theme' => self::getThemeHook($this->getPluginId()), + ]; + } + + /** + * Gets theme hook from plugin ID. + * + * @param string $pluginId + * Plugin id. + * + * @return string + * Theme hook. + */ + public static function getThemeHook($pluginId) { + return 'help_topic_' . $pluginId; } } diff --git a/core/modules/help_topics/templates/help-topic-config-basic.html.twig b/core/modules/help_topics/templates/help-topic-config-basic.html.twig new file mode 100644 index 0000000000..8108c34017 --- /dev/null +++ b/core/modules/help_topics/templates/help-topic-config-basic.html.twig @@ -0,0 +1,14 @@ +{% set regional_url = render_var(url('system.regional_settings')) %} +{% set information_url = render_var(url('system.site_information_settings')) %} +{% set datetime_url = render_var(url('entity.date_format.collection')) %} +

{% trans %}The settings for your site are configured on various administrative pages, as follows:{% endtrans %}

+
+
{% trans %}Site name, slogan, and email address{% endtrans %}
+
{% trans %} + On the Basic site settings page, which you can reach in the main Manage administrative menu, by navigating to Configuration > System > Basic site settings. + {% endtrans %}
+
{% trans %}Time zone and country{% endtrans %}
+
{% trans %}On the Regional settings page, which you can reach in the main Manage administrative menu, by navigating to Configuration > Regional and language > Regional settings.{% endtrans %}
+
{% trans %}Date and time formats{% endtrans %}
+
{% trans %}On the Date and time formats page, which you can reach in the main Manage administrative menu, by navigating to Configuration > Regional and language > Date and time formats.{% endtrans %}
+