Commit 10c41e77 authored by larowlan's avatar larowlan

Issue #3079810 by jhodgdon, andypost, mikelutz: core/help_topics directory does not work

(cherry picked from commit e0f9dba3)
parent 73c6568f
......@@ -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']
......
......@@ -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()
);
......
......@@ -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());
}
......
......@@ -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
......
......@@ -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
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment