diff --git a/core/modules/help_topics/help_topics.services.yml b/core/modules/help_topics/help_topics.services.yml index aff7698abc5ecdeecd56f3cf75cd1f02187b9a4a..ed6a59df0e2b422843452beb3c260ab06ca7877c 100644 --- a/core/modules/help_topics/help_topics.services.yml +++ b/core/modules/help_topics/help_topics.services.yml @@ -7,7 +7,7 @@ services: public: false plugin.manager.help_topic: class: Drupal\help_topics\HelpTopicPluginManager - arguments: ['@module_handler', '@theme_handler', '@cache.discovery'] + arguments: ['@module_handler', '@theme_handler', '@cache.discovery', '@app.root'] help.twig.loader: class: Drupal\help_topics\HelpTopicTwigLoader arguments: ['@app.root', '@module_handler', '@theme_handler'] diff --git a/core/modules/help_topics/src/HelpTopicPluginManager.php b/core/modules/help_topics/src/HelpTopicPluginManager.php index 40efa85106308239bf836d7d2fe6413209f1dd80..b2a94fc348b83b9114822da4ab67af5fb7178c88 100644 --- a/core/modules/help_topics/src/HelpTopicPluginManager.php +++ b/core/modules/help_topics/src/HelpTopicPluginManager.php @@ -93,6 +93,13 @@ class HelpTopicPluginManager extends DefaultPluginManager implements HelpTopicPl */ protected $themeHandler; + /** + * The app root. + * + * @var string + */ + protected $root; + /** * Constructs a new HelpTopicManager object. * @@ -102,8 +109,10 @@ class HelpTopicPluginManager extends DefaultPluginManager implements HelpTopicPl * The theme handler. * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend * Cache backend instance to use. + * @param string $root + * The app root. */ - public function __construct(ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, CacheBackendInterface $cache_backend) { + public function __construct(ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, CacheBackendInterface $cache_backend, $root) { // Note that the parent construct is not called because this not use // annotated class discovery. $this->moduleHandler = $module_handler; @@ -112,6 +121,7 @@ public function __construct(ModuleHandlerInterface $module_handler, ThemeHandler // Use the 'config:core.extension' cache tag so the plugin cache is // invalidated on theme install and uninstall. $this->setCacheBackend($cache_backend, 'help_topics', ['config:core.extension']); + $this->root = (string) $root; } /** @@ -121,7 +131,7 @@ protected function getDiscovery() { if (!isset($this->discovery)) { $module_directories = $this->moduleHandler->getModuleDirectories(); $all_directories = array_merge( - ['core'], + ['core' => $this->root . '/core'], $module_directories, $this->themeHandler->getThemeDirectories() ); diff --git a/core/modules/help_topics/src/HelpTopicTwigLoader.php b/core/modules/help_topics/src/HelpTopicTwigLoader.php index c945f526ddfca6d9d347a866c4fbaa1a723daa2b..b785736f1968a665c8de518c01fbdf69b1f05c82 100644 --- a/core/modules/help_topics/src/HelpTopicTwigLoader.php +++ b/core/modules/help_topics/src/HelpTopicTwigLoader.php @@ -44,7 +44,8 @@ class HelpTopicTwigLoader extends \Twig_Loader_Filesystem { public function __construct($root_path, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) { parent::__construct([], $root_path); // Add help_topics directories for modules and themes in the 'help_topic' - // namespace. + // namespace, plus core. + $this->addExtension($root_path . '/core'); array_map([$this, 'addExtension'], $module_handler->getModuleDirectories()); array_map([$this, 'addExtension'], $theme_handler->getThemeDirectories()); } diff --git a/core/modules/help_topics/tests/src/Functional/HelpTopicsSyntaxTest.php b/core/modules/help_topics/tests/src/Functional/HelpTopicsSyntaxTest.php index a8ef4eb2f7b10050177067f4a07ddfcdf543956e..c2f3b016a73b26e1d8f816b50f2e86f4b51cf515 100644 --- a/core/modules/help_topics/tests/src/Functional/HelpTopicsSyntaxTest.php +++ b/core/modules/help_topics/tests/src/Functional/HelpTopicsSyntaxTest.php @@ -42,7 +42,7 @@ public function testHelpTopics() { $directories = $module_directories + $theme_directories + $this->listDirectories('profile'); - $directories['core'] = 'core/help_topics'; + $directories['core'] = \Drupal::service('app.root') . '/core/help_topics'; $directories['bad_help_topics'] = \Drupal::service('extension.list.module')->getPath('help_topics_test') . '/bad_help_topics/syntax/'; // Filter out directories outside of core. If you want to run this test diff --git a/core/modules/help_topics/tests/src/Unit/HelpTopicDiscoveryTest.php b/core/modules/help_topics/tests/src/Unit/HelpTopicDiscoveryTest.php index 6457cf75b347fd4ca8678fe8bd0f52ba92623819..cc319dfa8716c1c949e8c91673f960ddec6773aa 100644 --- a/core/modules/help_topics/tests/src/Unit/HelpTopicDiscoveryTest.php +++ b/core/modules/help_topics/tests/src/Unit/HelpTopicDiscoveryTest.php @@ -170,6 +170,29 @@ public function testHelpTopicsExtensionProviderSpecialCase() { $this->assertArrayHasKey('core.topic', $discovery->getDefinitions()); } + /** + * @covers ::findAll + */ + public function testHelpTopicsInCore() { + vfsStream::setup('root'); + $topic_content = <<<EOF +--- +label: Test +--- +<h2>Test</h2> +EOF; + + vfsStream::create([ + 'core' => [ + 'help_topics' => [ + 'core.topic.html.twig' => $topic_content, + ], + ], + ]); + $discovery = new HelpTopicDiscovery(['core' => vfsStream::url('root/core/help_topics')]); + $this->assertArrayHasKey('core.topic', $discovery->getDefinitions()); + } + /** * @covers ::findAll */