Right now hook_help has to be invoked to find out if there are help texts for a given path. Possibly more efficient and certainly much more flexible would be a help text registry, stored in the database.
Similar to the menu, theme and (hopefully soon) functions are handled, the registry of help texts could be built periodically by invoking hook_help and getting structured help data. This data could be as simple as a path and the message. Then finding help messages for a path would be a matter of executing a query similar to the one that chooses a router callback.
In fact, it is possible that we could implement the help system as an extension of the menu system: 'help callback' and 'help parameters' in menu router items would make the help system infinitely more flexible.
Advantages of a more robust help system:
- hook_help_alter: lets you alter help texts
- modules that allow admins to inject or edit help texts
- export and import of help texts
| Comment | File | Size | Author |
|---|---|---|---|
| #35 | 244090.patch | 1.26 KB | dawehner |
| #27 | help2.module.txt | 4.9 KB | xano |
| #27 | help2.view_.inc_.txt | 2.02 KB | xano |
| #27 | help2.install.txt | 870 bytes | xano |
| #27 | help2.info.txt | 173 bytes | xano |
Comments
Comment #1
merlinofchaos commentedHey, have a look at the advanced help module I wrote yesterday.
Comment #2
robertdouglass commentedI like this: I write somewhere "Gee, it would be nice to have..." and you deliver it, all wrapped up with a ribbon. Thanks!
Comment #3
douggreen commentedLIVE FROM THE MINNESOTA SEARCH SPRINT... We're discussing how to integrate help search into search. The simplest solution is to implement a help_search, however the problem is that we don't have a registry of the available help paths. One solution is to change hook_help() to return an array, rather than have a switch statement there.
Comment #4
douggreen commentedAdvanced help looks promising, ... but we need to integrate help text into the search indexes, and not provide a completely new search interface that is just for help. If the advanced help module implemented a hook_search, and put this information in the search_index, then we'd be half way there, the second half being Souvent22's #252211 unified search form.
Comment #5
merlinofchaos commentedadvanced help does. However, it is much more user friendly for help search to have its own UI. I actually did a lot of work to keep the search from going back to the core search pages, because it's really jarring to search help and get taken to the search paths.
Comment #6
douggreen commented"However, it is much more friendly for help search to have its own UI." Is this a comment about how bad the current UI is? I'll install your module and look at it closer.
This idea that we do "node" searches or "user" searches or "help" searches is antithetical to real use cases. As a user, I don't really think about what I'm trying to find in these terms. I just want to find something. We are talking about a unified search system, that will show results from all help on one page. So if I search for "foo", it will display the results from node, user, help, panels (something I'll probably write and submit to you) and maybe views. All of these would store a sid/type pair in the {search_index} table, and we would get the results sorted by relevancy all at once (that's the dream goal at least). If you wanted to search just help, that would be possible too.
Comment #7
merlinofchaos commentedYea, I don't want users searching node content to get access to the help to administer Views on my site. I disagree what what you suggest is actually completely desirable, in part because access control on searching is quite hard.
Comment #8
drewish commentedi'm totally in favor of a hook_help_alter. one of the biggest hassles for me is that clients hate drupal's built in help text and there's not an easy way to change it without hacking core.
Comment #9
xanoIMHO hook_help_alter() is nothing more than a way to patch up Core instead of actually improving it.
To make the help searchable we can do two things:
The second option allows for help pages that may change. See Dynamic Help for more information. An example of hook_help() according to the second method:
In this example the help is statically cached to prevent all texts from being rendered more than once during one page load. This will probably only boost performance when users are searching help (need more info on this). This is just a sketch, so please comment.
Comment #10
damien tournoud commentedThis is *not* an option. In order to get the most gain from the registry, we need to kill the current hook_help implementation and get rid of that module_invoke_all() called virtually at every page request.
Comment #11
xanoWhen a module is being enabled hook_help() can be invoked once to save all paths to the database. At every page request a DB call can be made to see which help paths match the current URI and to which modules the matches belong. If any matches are found, render the help by calling hook_help() only for those modules for which there are matches.
Comment #12
robertdouglass commentedI think the answer is to integrate help with the menu system.
Then we can have a hook_help_alter(), or we could just use hook_menu_alter().
This would give us a registry of help texts similar to the registry of menu items.
Comment #13
drewish commentedi think robertDouglass's idea of the menu system integration is probably the best one. we can reuse the existing caching and altering systems and get the help path integration for free.
Comment #14
xanoComment #15
merlinofchaos commentedMany of these ideas are not compatible with Gurpartap's existing help system patch. As a proponent of that system, I'd like to at least see ideas that are not compatible with it integrated into it or modified or hold off until that patch is resolved.
Comment #16
drewish commentedxano, we're going to be rewriting something either way. why wouldn't normal page callback be possible? it's just hanging off of the existing callback, robert just omitted that bit.
it'd totally be possible to have separate help files. obviously we'd need to write some code but you could allow something like:
With this method you've got your help easily associated with your path. No need to for wacky preg_matches in the hook_help any longer to match certain paths.
Comment #17
xanoI see what you're doing... Hmm. It doesn't look clean, since there hardly is a separate help system anymore, but it would definitely work.
As to points two and three:
There's no need to bother with different languages, since all help texts are passed on through t() and should be translated just like any other string.
Comment #18
drewish commentedXano, I don't see the need for keeping the some_help() function. If we follow the pattern used for menu titles 'help' => would be static strings and 'help callback' would used for loading strings dynamically.
Comment #19
xanoI don't like the idea of one way for static strings and another for dynamic ones. I suggest using one method for both cases to keep things simple.
Comment #20
xanoOne more thing I thought of: how do we let help.module index all dedicated help pages? Going through all results of module_invoke_all('menu') and check whether the paths of the items start with 'admin/help' doesn't look very efficient to me.
I am still curious if pages behind menu callbacks are cached/searchable. If not, we need to add them to the search index at the same time as we're indexing them.
Comment #21
robertdouglass commented@xano: we'd extend the menu router database table to store help texts. Then they could be indexed and searched. This is totally in line with the other things the menu router does, imo.
Comment #22
robertdouglass commented@xano: note that this system could also lead to help texts in static files - it would all depend on the implementing callback functions we wrote.
Comment #23
xanoI don't know about actually storing help texts. This doesn't work for dynamic texts and like I said before I don't support using one solution for static texts and another for dynamic ones.
We need a concrete solution for searching and indexing dedicated help pages (I doubt we need to do this for the additional help texts at other pages). My suggestion is to let help.module invoke hook_menu() on a regular basis (because the menu isn't static) and check for dedicated help pages. It saves the paths to and titles of these help pages to its own table together with the module they belong to so it can build the help index from there. As soon as a user searches the help, help.module checks these paths, calls the callbacks (if the user has permission) and lets search.module search the content. How do we check whether a menu item points to a dedicated help page? By checking paths like admin/help/[module_name]/[foo]/[bar] for 'admin/help' at the beginning and extract the module name?
Comment #24
merlinofchaos commentedGurpartap's help system patch already puts help text in separate, static files (Translatable) and already indexes them for a search engine. I really feel that the energy spent here would be better reviewing and extending this patch that already exists: http://drupal.org/node/299050 -- much of this conversation is re-inventing already written code.
Comment #25
xanoDynamic files are translatable as well. All you can't do with them is cache them.
No offence, but I think it's better to walk both ways and see which is best than to rely on only one.
Comment #26
robertdouglass commentedjust for the record, even though this is my issue, I totally agree with merlinofchaos that people should be jumping in on #299050 instead of pursuing a parallel discussion. This issue was created at a time when I was evaluating Gurpartap's work, merlinofchaos' Advanced Help, and my own ideas. What is being presented in #299050 is far superior to what we have now.
Comment #27
xanoSuperior in what way? Personally I find a lot of parts of that patch are a step backwards: pop-ups, HTML that is not in theme() functions, etc. The attached files are my attempt to rewrite the help system implementing robertDouglass' idea of using the menu system. I also added a per-module permission for help pages. When I started working on it I wasn't really intending on posting it here, so don't laugh about its name :-P (help2.module). The module file is the only file that's actually working yet. Modules may define dedicated help pages by simply adding a menu callback with a path starting with 'admin/help'. Help for existing pages needs yet to be implemented by adding the 'help callback', 'help arguments' and 'help access' properties.
So far there's not really much to see, since most functions that actually _view_ help pages still rely on hook_help() being used my modules, but if you take a look at help2.module I think you get a good idea of things work.
I don't mean to go against Gurpartap Singh, I just don't like his idea and I tried to implement robertDouglass' idea instead. In the end I think it works even better than expected, that's why I'd like to continue working on it.
//edit: 'help access' is not necessary. Users that have permission to access a page should also see the help for that page if there is any.
Comment #28
robertdouglass commentedAnd here's the exploration I did some weeks back when I looked at the issue.
Comment #29
robertdouglass commentedI think I might have been taking advanced_help module and trying to put it directly into core, so the syntax in my path is to get the help arguments from the menu item:
If I remember right, this patch, with the advanced_help module enabled, was enough to put adv help texts on the page. But don't take my word for it :P
Comment #30
Anonymous (not verified) commentedbookmark
Comment #31
sun.core commentedThis is anything but "needs more info". Interesting ideas in here.
Comment #32
sun#591682: Config pages are effectively hardcoded to some subcategory of 'admin/config'
and
#699848: admin/by-task is confusing since it lacks links to config pages and looks similar to admin/config and friends
both clearly identified that page-related help needs to be tied to a menu router item context instead of just paths.
Comment #33
pancho#32:
Absolutely agree, and after refocussing on this aspect, IMHO it is a task now.
Any perspective on this for D8? Help module's code is so much old-school, ugly and inflexible...
Comment #34
andypostFor multilingual sites now there's no ability to access
{langcode}/node/xxx/editpage because ofFatal error: Call to a member function bundle() on a non-object in /home/andypost/www/core8/core/modules/node/node.module on line 134So filed #2092641: node_help() does not allows to edit node translations
also related #2091399: [META] Remove menu_get_object()
Comment #35
dawehnerComing from #788900: Deprecate and remove usages of arg() catch opened the idea to replace $path and $arg with basically the route name and route parameters.
Even I agree that this fixes some potential bugs when you replace the path but keep the route name we kind of already a similiar behavior.
I am not sure whether
can be supported with this syntax.
At least we need to fix the following kind of bug.
Comment #36
larowlanRelated #2183113: Update hook_help signature to use route_name instead of path - note in my (wip) patch for that I'm using help.main for the admin/help page and help.page.{module} for admin/help/#modulename
Comment #37
tim.plunkettChecked with @andypost, the hook_help bug he described was cleaned up, and we have a path forward in #2183113: Update hook_help signature to use route_name instead of path, so marking this a dupe.