Problem/Motivation

You cannot put core help topics into the core/help_topics directory. If you do, you get an exception saying something like this:

Uncaught PHP Exception Drupal\\Component\\Discovery\\DiscoveryException: "core/help_topics/core.ui_accessibility.html.twig should begin with '0.'" at /home/jhodgdon/gitrepos/drupal-nonmaintainer/core/modules/help_topics/src/HelpTopicDiscovery.php line 105

We will need to be able to do this once we get to #3025577: Move help topics to core or the correct modules as part of finalizing making this stable.

Proposed resolution

Fix this bug now so that when we do move the topics, they will work fine. But don't add any topics to core/help_topics now, because we want everything contained in core/modules/help_topics for now.

So, we should make a patch that adds a topic for testing. Then make a new patch that just fixes the bug without adding the topic, and get that committed.

Remaining tasks

Patches. Commit.

User interface changes

None.

API changes

New argument for the HelpTopicPluginManager constructor.

Data model changes

None.

Release notes snippet

None needed.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhodgdon created an issue. See original summary.

andypost’s picture

Looks it needs to threat "core" as special case

jhodgdon’s picture

Could be. I didn't look into it yet, just created the issue when I found it and moved on.

jhodgdon’s picture

Status: Active » Needs review
FileSize
2.44 KB

Here's a patch that we can consider to be a test-only patch, because it makes it so if you enable Help Topics and go to admin/help, you get this error. It just moves all the topics in core/modules/help_topics/help_topics whose names begin with "core" to the core/help_topics directory.

I'm working on a patch for the code.

jhodgdon’s picture

OK, that was easy. Here's the 3-line code patch.

Status: Needs review » Needs work

The last submitted patch, 5: 3079810-5.patch, failed testing. View results

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

jhodgdon’s picture

OK. I think we need some of what was in the patch on #3072312: Review/fix/delete existing help topics on here. Namely, we should move the topics in core/modules/help_topics/help_topics that pertain to other modules into those modules, remove the discovery code that allows help topics to be in that directory temporarily, and remove the test that verifies the non-help-topics topics are not displayed if their module is absent.

However, I'm not sure it is OK to do this right now. We might need to wait until we are ready to go Stable to move those topics around. I'm just not sure if help topics can spill out across Core before the Help Topics module is stable.

I've asked in Slack about this... We may need to defer actually moving the modules around until we're closer to stable.

jhodgdon’s picture

Issue summary: View changes

As a note on this issue... We cannot actually move the topics into the core directory at this time -- I asked in Slack and found out from @xjm that all of the code *and topics* related to the Help Topics module need to stay under core/modules/help_topics until we are Stable.

However, I think we should still fix this bug so that when we do move the topics, they will work fine. So my suggestion is that we make a patch that moves 1 topic and verifies it works (obviously fixing the code at the same time). Then make a new patch that just fixes the bug without moving the topic, and get that committed.

Then when we get to #3025577: Move help topics to core or the correct modules (which will actually move the topics), we will be ready.

Summary update...

andypost’s picture

I think better to use a test with vfs to unittest core dir for discovery, that's better scope for the issue

andypost’s picture

+++ b/core/modules/help_topics/src/HelpTopicDiscovery.php
@@ -97,6 +97,9 @@ public function findAll() {
+        if (!$provider) {
+          $provider = 'core';

I bet "core" as default/fallback is wrong, condition should be smarter to detect that topics coming really from core

jhodgdon’s picture

Good idea in #10.

Good though in #11, but I think it is OK. A few lines below that, there is a discovery fail if the provider doesn't match the file name prefix, so I think it is probably good enough. I guess we should look at the code for the directory scanner and see what the circumstances are for returning nothing as the provider, but since we're only scanning module, profile, theme, and core directories, I think it is probably correct.

jhodgdon’s picture

Assigned: Unassigned » jhodgdon

I will work on a test using a VFS today. And incidentally this issue is limited to making help topics inside core/help_topics work, not removing the ability to have all the help topics inside core/modules/help_topics.

jhodgdon’s picture

Oh gracious. I put some code into the HelpTopicDiscoveryTest, to test that the Core directory worked, and it passed.

So the problem is actually in HelpTopicPluginManager::getDiscovery(). It is supposed to pass an array of directories **keyed by provider** to the HelpTopicDiscovery constructor. But instead it is doing:

      $all_directories = array_merge(
        ['core'],
        $module_directories,
        $this->themeHandler->getThemeDirectories()

No array key on ['core'] there! That is the problem. Also that directory needs to be fully mapped out, not relative to the app root. So that is fairly easy to fix.

By the way, I don't think we can inject something into the existing core directory structure using a VFS -- it's a separate file system -- so I think the only way to verify that the fix in the plugin manager works is to (temporarily) add at least one help topic in the core/help_topics directory. Given that, here are some patches:
- Patch to commit adds to the unit test, fixes another test, and fixes the plugin manager. This involves injecting the app root into the plugin manager.
- Test-only patch adds a test file to the core/help_topics directory to illustrate the problem, but we cannot commit this now because we don't want topics there (plus this is a test topic).
- Fix-plus-patch adds these two together, to demonstrate that the patch we should commit will work when we get to the point of adding topics to core when the module is stable. We also cannot commit this now, but it illustrates that the fix works. At least, I spot checked a few tests and it seems to be OK, but let's see if the bot agrees.

No interdiff because this is not related to the previous patches.

andypost’s picture

Related may affect patch which is awesome!

jhodgdon’s picture

Issue summary: View changes

Yeah, also depending on the timing, if we have already marked Help Topics as Beta, we may need to add a deprecation notice about needing another argument for the plugin manager constructor (API change).

The last submitted patch, 14: 3079810-13-test-only-FAIL.patch, failed testing. View results

The last submitted patch, 14: 3079810-13-test-with-fix-DO-NOT-COMMIT.patch, failed testing. View results

jhodgdon’s picture

Status: Needs review » Needs work

Looks like TestHelpSearch still fails with this patch, and there is also a coding standards violation. I will make a new patch in a few hours.

jhodgdon’s picture

It turned out that the TwigLoader class also needed to know about the core directory. Now if you have this test core topic added to your system, you can view the page. However, the Help Search test doesn't pass locally -- the uninstall test is failing. Not sure why, because if I manually go and uninstall the module, there is not a problem on the help page... though this is not the same as the test, I think -- there may be some cache clearing happening. Not sure.

Anyway, let's see what the bot says. Here's an interdiff, and two of the 3 patches updated -- to fix the Twig problem and also the coding standards problem (the test-only patch did not change).

jhodgdon’s picture

OK, the bot says the patch is ready to go. Any reviews please? I think it would be good to get this in before Help Topics beta, because of small API change.

larowlan credited mikelutz.

larowlan’s picture

For Symfony 5 compatibility, we're working on #3074585: [Symfony 5] Replace app.root and site.path string services with container parameters - essentially in SF5, services cannot be primitives like string etc.

So in that issue we're using an object that implements __toString.

I discussed this issue with @mikelutz who recommended we cast the app root to a string in the __construct method for future compatibility with that issue.

jhodgdon’s picture

OK, here's a new patch that does that (just edited the previous patch file, and I only did it in the To Commit patch).

Only this line changed in HelpTopicPluginManger (added cast to string):

    $this->root = (string) $root;
jhodgdon’s picture

@larowlan is too fast for me -- commit on #3087496: Change prefixes of Help Topics machine names to help and make sure APIs are marked @internal conflicted in the services.yml file. Here's a new patch that should apply.

andypost’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/modules/help_topics/src/HelpTopicPluginManager.php
@@ -112,6 +121,7 @@ public function __construct(ModuleHandlerInterface $module_handler, ThemeHandler
+    $this->root = (string) $root;

I'd say it needs comment or todo why tycasting but it already linked to it as related

  • larowlan committed e0f9dba on 9.0.x
    Issue #3079810 by jhodgdon, andypost, mikelutz: core/help_topics...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed e0f9dba and pushed to 9.0.x. Thanks!

c/p to 8.8 and 8.9

  • larowlan committed 10c41e7 on 8.8.x
    Issue #3079810 by jhodgdon, andypost, mikelutz: core/help_topics...
  • larowlan committed 56f670c on 8.9.x
    Issue #3079810 by jhodgdon, andypost, mikelutz: core/help_topics...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.