Problem/Motivation

On #3087218-71: Help searches fail if site is not fully indexed, and users do not know why, catch requested

The code in help_topics_modules_uninstalled() could be moved to a _helper_function(), and that would save having to explain what we're doing here.

This code is located in the file core/modules/help_topics/help_topics.module.

More explanation:

On the parent issue, we implemented hook_modules_installed(), hook_themes_installed(), hook_modules_uninstalled(), and hook_themes_uninstalled(). All 4 needed to call some of the same code. The way it was implemented, we put the necessary code in hook_modules_uninstalled() and then called this function from the other 3.

What catch is asking for instead is that we make a helper function whose name starts with _help_topics_ to do the common operations, and call that instead from all four functions.

Steps to reproduce

Proposed resolution

Move the common code for these 4 hooks into a new helper function in help_topics.module whose function name starts with _help_topics_.

Remaining tasks

1. Make a patch to do the above.
2. Review the patch.
3. Commit the patch.

User interface changes

None.

API changes

Not really. Functions starting with _ are not part of the public API, and the same code will still be executed for each of these hooks.

Data model changes

None.

Release notes snippet

Not necessary.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhodgdon created an issue. See original summary.

guilhermevp’s picture

Assigned: Unassigned » guilhermevp
guilhermevp’s picture

Assigned: guilhermevp » Unassigned
Status: Active » Needs review
FileSize
2.85 KB

Sending patch. Please review.
Made the _helper_function() as requested by Catch and updated documentation as well.

andypost’s picture

Status: Needs review » Needs work
+++ b/core/modules/help_topics/help_topics.module
@@ -60,45 +60,49 @@ function help_topics_theme() {
+  //Ensure that index state is updated when a module is installed.
...
+  //Ensure that index state is updated when a module is installed.
...
+  //Ensure that index state is updated when a module is installed.
...
+  //Ensure that index state is updated when a module is installed.
...
+
+function _helper_function(array $modules) {

1) this function needs proper naming for example _help_topics_search_update()

2) needs doc-block and removal of similar inline comments

guilhermevp’s picture

Assigned: Unassigned » guilhermevp
guilhermevp’s picture

Assigned: guilhermevp » Unassigned
Status: Needs work » Needs review
FileSize
2.72 KB
1.52 KB

@andypost thanks for the feedback!

Please review the new patch.

andypost’s picture

Status: Needs review » Needs work

It should get array $extensions as argument but all calling places pass empty array

guilhermevp’s picture

Status: Needs work » Needs review
FileSize
1.49 KB
2.74 KB

Sending new patch.

Thanks again for the time and patience.

andypost’s picture

Status: Needs review » Needs work

Great! Mostly done)

_helper_topics_search_update() needs properly declared doc-block according to https://www.drupal.org/docs/develop/standards/api-documentation-and-comm...

guilhermevp’s picture

Is this the correct doc block format for this situation?

/**
 * Ensure that index state is updated when a module is installed.
 *
 * @param array $extensions
 *   Array containing the names of the extensions. 
 */
function _helper_topics_search_update(array $extensions) { 
andypost’s picture

As it used for modules and themes we call it extension in core 8+

guilhermevp’s picture

Status: Needs work » Needs review
FileSize
2.82 KB
855 bytes

Thanks for all the help. Sending patch for review.

jhodgdon’s picture

Thanks for the patch! I was going to review it but it was easier to make an interdiff. One big functional point: The array of extensions should only be passed in when modules are being uninstalled. Not for the other 3 cases. Anyway here is a fixed-up patch with a bunch of changes.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Thanks 👍 looks ready and should be green, OTOH array could use kinda EntensionInterface[] for doc block

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 13: 3209139-13.patch, failed testing. View results

jhodgdon’s picture

Status: Needs work » Reviewed & tested by the community

Test fail was in QuickEditFileTest. Looks like a random glitch.

jhodgdon’s picture

I believe $extensions is an array of strings, not of extensions. It's not documented what it is here:
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Extension...
But if you look at where it's invoked, you can see it's a plain array of strings:
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Extension...

andypost’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
943 bytes
2.96 KB

Sorry, I was wrong so here fix - string[] and void to polish )

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Changes look good to me. You had already RTBC'd the previous patch, so I think it is OK for me to RTBC your changes.

  • catch committed fd56500 on 9.2.x
    Issue #3209139 by guilhermevp, andypost, jhodgdon: Create helper...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed fd56500 and pushed to 9.2.x. Thanks!

Status: Fixed » Closed (fixed)

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