Problem/Motivation

#2592487: [meta] Help system overhaul explains a lot of current problems with the help system, which we try to solve in this issue.

Generate overview

Much like menu links, we could move hook_help definitions into a yml file, which looks like the following:

$module.help.yml

module:
  template: help/module.html.twig
other_module_route:
  template: help/other_module_route.html.twig

In each individual template you can then use twig intersected with HTML as you like:

Before

$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Node module manages the creation, editing, deletion, settings, and display of the main site content. Content items managed by the Node module are typically displayed as pages on your site, and include a title, some meta-data (author, creation time, content type, etc.), and optional fields containing text or other data (fields are managed by the <a href=":field">Field module</a>). For more information, see the <a href=":node">online documentation for the Node module</a>.', array(':node' => 'https://www.drupal.org/documentation/modules/node', ':field' => \Drupal::url('help.page', array('name' => 'field')))) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';

After

<h3>{% trans %}About{% endtrans %}</h3>
{# you get the idea #}

## More details.
Internally, much like menu links it could use plugins which would make things easier and more flexible,
as it would enable some of the more tricky usecases.

  1. It would also lower the barrier for users with little php knowledge to contribute documentation if they only need to edit a yaml file where it's clearer what's where and how the syntax works.
  2. Complex cases:
    There are some weird examples in core:
      if ($route_name != 'node.configure_rebuild_confirm' && $route_name != 'system.batch_page.normal' && $route_name != 'help.page.node' && $route_name != 'help.main'
        && \Drupal::currentUser()->hasPermission('access administration pages') && node_access_needs_rebuild()) {
        if ($route_name == 'system.status') {
          $message = t('The content access permissions need to be rebuilt.');
        }
        else {
          $message = t('The content access permissions need to be rebuilt. <a href=":node_access_rebuild">Rebuild permissions</a>.', array(':node_access_rebuild' => \Drupal::url('node.configure_rebuild_confirm')));
        }
        drupal_set_message($message, 'error');
      }
    

    If you put it into plugins it could do the following:

    node_rebuild:
      class: Drupal\node\Plugin\Help\NodeRebuild
    
    class NodeRebuild {
      public helpHtml() {
        ...
      }
    }
    
  3. It allows to write a contrib module that allows to add UI configurable help texts, using derivatives.
  4. Cross-linking between help texts could be made easy using a help function help_page('other_name')
  5. The plugin discovery could be expanded to core/themes/install profiles, not just modules
  6. It addresses the UX problems, given that twig templates are way easier to work with
  7. With the yml files you can add additional metadata, like hierarchy information on an additional step.

Addressing points of the meta issue

  • [non topical] Each module can only provide one main help page for the admin/help listing

    The plugin based approach allows to add additional metadata later, which for example would allow to introduce topics. This should not be part of the initial issue, but could be added later, with some more planning.

  • ] There is no way to search help.

    This is not addressed by this issue. Help is special as it always contains some form of templateing, so a custom search will be needed for every approach.

  • [markup] Markup is being provided inside hook_help(), especially for the module help pages, via concatenating translatable strings with HTML tags.

    HTML already has quite some semantic information, like <header>. On top of that proposal though we could introduce .markdown.twig or .restructed_text.twig. This could be done in a follow up. Explictness in templates allows us to deal with that. <3

  • [authoring] The current hook_help() syntax is difficult for Documentation writers, who may not be PHP programmers. This is also mentioned as a problem in #2188753: Get rid of hard-coded markup in hook_help() implementations.

    This is addressed by the issue, because yml + twig is way easier than PHP

  • [cross-links] There is not a great way to cross-link to other topics. Currently this is done with PHP code (to make sure the other module is enabled) and placeholders for the URLs.

    We could have a custom twig help function: {% help_url('name') %}

  • [code] hook_help() is used for two different purposes, and it's kind of a mongrel: the module help pages are specified by responding to a fake path/route, which is a little bit weird. Also, hooks are outdated in general. We have moved many hooks and page generators into plugins, controllers, or YML files.

    We could have different help types, either in one file or in multiple:

    foo:
      type: module
      template: ...
    bar:
      type: route
      route_name: bar
      template: ...
    
  • [limited list] There is a core Tour module that provides a different type of help, but tours are not listed on the admin/help page either. Contrib modules may also provide some form of help, but they're not listed either.

    Given the plugin based approach the tour module could integrate with the help system using a custom plugin derivative, which exposes every tour thing and exposes it as a help plugin as well.

  • [must enable] There is no way to see the module overview pages without the module being enabled first. This has been filed as a separate issue: #2587469: allow hook_help to run on modules which are not enabled.

    This is not yet enabled by this issue to be honest. Its a tricky problem. There are bits here, for which using twig could help. Linking for example could be wrapped easily.

  • [no admin] There is no way for a site builder to add pages to the help, except by writing a module to implement hook_help(). This would still not let them use the Help system to build help pages for content editors or other site users, since it would still be one page per module.

    Using plugin derivatives would allow us to write a config entity based provider one day, with a UI and what not.

  • [glossary] It might be useful to have a glossary of terminology that modules/themes could add entries to. This is a separate issue: #2701289: Glossary to extend the Help system

    Not really addressed by this issue. Theoretically this could be just another help type though.

Proposed resolution

Remaining tasks

  • Agree on the general direction
  • Get approval by help system maintainer
  • ...

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#3 2820166-3.patch6.69 KBdawehner
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner created an issue. See original summary.

dawehner’s picture

Issue summary: View changes
dawehner’s picture

FileSize
6.69 KB

Here is an example in code to show how much twig potentially makes things easier.

ifrik’s picture

Would this mean that the help text would be available even if the module is not enabled?

In that case it would be a great improvement because it would allow users to better assess whether a module (or a especially submodule) does what the user needs.
The threshold of just enabling a module to have a look has become somewhat higher with the need to uninstall it (instead of simply disabling it again), so it would encourage people more to explore the options first.

It would also lower the barrier for users with little php knowledge to contribute documentation if they only need to edit a yaml file where it's clearer what's where and how the syntax works.

dawehner’s picture

Issue summary: View changes

Thank you for the feedback @ifrik

In that case it would be a great improvement because it would allow users to better assess whether a module (or a especially submodule) does what the user needs.
The threshold of just enabling a module to have a look has become somewhat higher with the need to uninstall it (instead of simply disabling it again), so it would encourage people more to explore the options first.

Interesting idea. In the first place this wouldn't mean that, but potentially it could be explored, given that twig files are way more limited in their capabilities. One major problem though would be URLs pointing to pages in the system, for which the pages aren't available.

I added your last point to the issue summary. I totally agree with it.

jhodgdon’s picture

This idea is interesting... Linking to the Meta issue...

Also the Twig part seems fairly similar to
#1918856: Put each module's help into a separate Twig file
so adding that as Related as well.

Also... I just want to say that this seems to be confusing/combining two things:

a) Module-level help -- the pages that are listed on the admin/help page, which summarize module functionality.

b) Page-level help -- the bits of help that modules can add to particular routes/pages in the System Help block.

I am not sure which things this would take care of, but it seems like they are NOT the same (although both are covered by the current hook_help() system) and it would be good to separate them out into two separate systems.

See also the list of features/problems at the top of #2592487: [meta] Help system overhaul. I don't think this proposal really addresses very many of the problems.

dawehner’s picture

Issue summary: View changes

I am not sure which things this would take care of, but it seems like they are NOT the same (although both are covered by the current hook_help() system) and it would be good to separate them out into two separate systems.

I was planning to separate them somehow in the yml file / or maybe into two yml files:

foo:
  type: module
  template: ...
bar:
  type: route
  route_name: bar
  template: ...

Would that work for you?

I don't think this proposal really addresses very many of the problems.

I Hope you don't assume I haven't read the meta issue.

Let me address that in the issue summary

jhodgdon’s picture

I really think that separating the module-level help and the route-level help into two completely different systems would be a good idea.

And really, having "topics" instead of "module-level" help would be great, because that would conceivably allow profiles and themes to provide topics as well, and for modules to provide more than one topic. Then the topics could even have titles.

However... why use Twig to provide the text? Twig is supposed to be used for theming, not for providing content/text. The content of pages is generally provided in form and render arrays, and I'm still not convinced (see the other issue I linked to in my last comment) that providing help content in Twig templates is a good idea. Twig templates can be overridden in a theme... not a great match for the functionality of providing help.

dawehner’s picture

@jhodgdon
I hear your worries. I primarily prefer twig, because it is known by a lot of people, and not a Drupalism.

And really, having "topics" instead of "module-level" help would be great, because that would conceivably allow profiles and themes to provide topics as well, and for modules to provide more than one topic. Then the topics could even have titles.

Could this be put in the metadata?

foo:
  type: topic
  title: topic_title:
  template: ...

but sure we could also have: $module.help.topic.yml and then put that kind of information in there. Having plugins allows us more flexibility.

However... why use Twig to provide the text? Twig is supposed to be used for theming, not for providing content/text

Note: Twig in its root is a template engine. A think which uses some kind of output and applies it to some other output. We use it in our theme system, but we can totally use twig templates outside of the theme system. We can use the twig system for itself.

jhodgdon’s picture

Agreed, the topic title could go into the YML metadata. And OK on Twig... it will just take some getting used to. :)

So. If we're going to have plugins... I just want to note that I have this:
https://www.drupal.org/sandbox/jhodgdon/2369943
I personally think it is a pretty good approach... and it all works, has tests, etc. And solves most/all of the problems in the Meta issue summary...

jhodgdon’s picture

And should this go into the Ideas queue?

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

markhalliwell’s picture

X-post: what I said here https://www.drupal.org/project/ideas/issues/2592487#comment-12477427 probably makes more sense within the context of this issue's discussion.

joachim’s picture

> However... why use Twig to provide the text? Twig is supposed to be used for theming, not for providing content/text.

What about making them markdown files?

So:

$module.help.yml

module:
  content: help/module.md
other_module_route:
  content: help/other_module_route.md

(Though as a side-note, I'd remove the 'help/' part, and just say that all help content must be in help/)

andypost’s picture

Markdown has the same hard issue with passing tokens, urls & route names at preprocessing

joachim’s picture

> passing tokens, urls & route names at preprocessing

Those should maybe be discussed at #2592487: [meta] Help system overhaul, because they're not currently mentioned there as required features.

jhodgdon’s picture

Markdown files would also not easily/obviously be translatable, especially not on localize.drupal.org, without considerable work:
- Would need to break it down to paragraph-sized chunks
- Would need to get it into the PO file

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

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

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jhodgdon’s picture

Status: Active » Closed (duplicate)
Related issues: +#2920309: Add experimental module for Help Topics

At this point, the planned patch for Help Topics looks a lot like this idea, except even simpler: the topics and their meta-data are both in Twig templates (no YAML files at all). So, I think we can now close this as a duplicate of #2920309: Add experimental module for Help Topics. If not, feel free to reopen. :)