Unverified Commit 56f670c8 authored by larowlan's avatar larowlan
Browse files

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

(cherry picked from commit e0f9dba3)
parent f5cd557c
...@@ -7,7 +7,7 @@ services: ...@@ -7,7 +7,7 @@ services:
public: false public: false
plugin.manager.help_topic: plugin.manager.help_topic:
class: Drupal\help_topics\HelpTopicPluginManager class: Drupal\help_topics\HelpTopicPluginManager
arguments: ['@module_handler', '@theme_handler', '@cache.discovery'] arguments: ['@module_handler', '@theme_handler', '@cache.discovery', '@app.root']
help.twig.loader: help.twig.loader:
class: Drupal\help_topics\HelpTopicTwigLoader class: Drupal\help_topics\HelpTopicTwigLoader
arguments: ['@app.root', '@module_handler', '@theme_handler'] arguments: ['@app.root', '@module_handler', '@theme_handler']
......
...@@ -93,6 +93,13 @@ class HelpTopicPluginManager extends DefaultPluginManager implements HelpTopicPl ...@@ -93,6 +93,13 @@ class HelpTopicPluginManager extends DefaultPluginManager implements HelpTopicPl
*/ */
protected $themeHandler; protected $themeHandler;
/**
* The app root.
*
* @var string
*/
protected $root;
/** /**
* Constructs a new HelpTopicManager object. * Constructs a new HelpTopicManager object.
* *
...@@ -102,8 +109,10 @@ class HelpTopicPluginManager extends DefaultPluginManager implements HelpTopicPl ...@@ -102,8 +109,10 @@ class HelpTopicPluginManager extends DefaultPluginManager implements HelpTopicPl
* The theme handler. * The theme handler.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* Cache backend instance to use. * 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 // Note that the parent construct is not called because this not use
// annotated class discovery. // annotated class discovery.
$this->moduleHandler = $module_handler; $this->moduleHandler = $module_handler;
...@@ -112,6 +121,7 @@ public function __construct(ModuleHandlerInterface $module_handler, ThemeHandler ...@@ -112,6 +121,7 @@ public function __construct(ModuleHandlerInterface $module_handler, ThemeHandler
// Use the 'config:core.extension' cache tag so the plugin cache is // Use the 'config:core.extension' cache tag so the plugin cache is
// invalidated on theme install and uninstall. // invalidated on theme install and uninstall.
$this->setCacheBackend($cache_backend, 'help_topics', ['config:core.extension']); $this->setCacheBackend($cache_backend, 'help_topics', ['config:core.extension']);
$this->root = (string) $root;
} }
/** /**
...@@ -121,7 +131,7 @@ protected function getDiscovery() { ...@@ -121,7 +131,7 @@ protected function getDiscovery() {
if (!isset($this->discovery)) { if (!isset($this->discovery)) {
$module_directories = $this->moduleHandler->getModuleDirectories(); $module_directories = $this->moduleHandler->getModuleDirectories();
$all_directories = array_merge( $all_directories = array_merge(
['core'], ['core' => $this->root . '/core'],
$module_directories, $module_directories,
$this->themeHandler->getThemeDirectories() $this->themeHandler->getThemeDirectories()
); );
......
...@@ -44,7 +44,8 @@ class HelpTopicTwigLoader extends \Twig_Loader_Filesystem { ...@@ -44,7 +44,8 @@ class HelpTopicTwigLoader extends \Twig_Loader_Filesystem {
public function __construct($root_path, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) { public function __construct($root_path, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) {
parent::__construct([], $root_path); parent::__construct([], $root_path);
// Add help_topics directories for modules and themes in the 'help_topic' // 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'], $module_handler->getModuleDirectories());
array_map([$this, 'addExtension'], $theme_handler->getThemeDirectories()); array_map([$this, 'addExtension'], $theme_handler->getThemeDirectories());
} }
......
...@@ -42,7 +42,7 @@ public function testHelpTopics() { ...@@ -42,7 +42,7 @@ public function testHelpTopics() {
$directories = $module_directories + $theme_directories + $directories = $module_directories + $theme_directories +
$this->listDirectories('profile'); $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/'; $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 // Filter out directories outside of core. If you want to run this test
......
...@@ -170,6 +170,29 @@ public function testHelpTopicsExtensionProviderSpecialCase() { ...@@ -170,6 +170,29 @@ public function testHelpTopicsExtensionProviderSpecialCase() {
$this->assertArrayHasKey('core.topic', $discovery->getDefinitions()); $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 * @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