Problem/Motivation
The hoverintent_functionality is currently set in the admin_toolbar_tools module which doesn't really make any sense, since this feature "should" actually work without admin_toolbar_tools.
https://git.drupalcode.org/project/admin_toolbar/-/blob/3.x/admin_toolba...
All of the settings for this feature are in admin_toolbar_tools when none of the display logic is in the module, but is in admin_toolbar instead, see:
https://git.drupalcode.org/project/admin_toolbar/-/blob/3.x/admin_toolba...
The JS file as well....
From what I can understand based on my review of module's code, the admin_toolbar_tools mostly adds links for entity bundles, admin operations (Flush cache, Run cron, Run updates, etc..), local tasks, etc... but doesn't act at all on the display logic.
Proposed resolution
Move everything related to the hoverintent_functionality out from the admin_toolbar_tools module to admin_toolbar.
Watch out for the update function to be added in the install file of the module, so the configuration on all sites could be properly updated.
Any comments, suggestions or feedback would be greatly appreciated.
Thanks in advance!
Issue fork admin_toolbar-3516995
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
dydave commentedComment #4
ressaThanks @dydave, always a great idea to optimize the code structure :)
I have tested the patch, but the hover stops working ... I need to click (or right-click) to expand a child item. The code itself, I have not looked at.
Also, I don't know what hoverintent is about ... so perhaps this sentence could be expanded, and briefly describe what it does?
... similar to how sticky is described (explanation emphasized by me):
Comment #5
dydave commentedThanks you so much @ressa !!
Did you try flushing the cache ?!
Very strange, my colleagues gave this a round of tests and reviews and it was working ...
Also, watchout, you need to run db updates after applying the patch or switching to the branch.
Totally agree with you!
I didn't want to change this so far, since it's going to break all translations ....
But since we're going for a new minor
3.6.0and are already introducing BC breaking changes (see: #3514075-5: unsafe usage of new static()) and this change in particular in this MR:Got me very worried and I made a lot of research to see how to handle changing a config or renaming it ....
That's also potentially BC breaking ...
So we're going for a new minor, definitely !
I'll create tonight the META issue: Road to 3.6.0, as you recommended previously.... Now the release plan is clear to me !
Let's go and break things 😅
I'll get the wording updated for this setting, definitely, based on your suggestions...
But please if you could: Try forcing a bit more the tests to work on your ENV locally ...
Everything seemed to work for my colleagues.
Stay tuned for rounds of changes from tonight and over the weekend !
Thanks again so much!
Comment #6
dydave commentedAlso, make sure you have the correct settings enabled on the config forms in the backend after running the DB updates, if you're updating from a stable or branch 3.x ....
Code :
https://git.drupalcode.org/project/admin_toolbar/-/merge_requests/132/di...
I've tested this a bit, switching from 3.x to this feature branch
3516995-move-the-hoverintentfunctionalityand run drush updb, and everything seemed to work fine ...But I'd like to get more testing feedback on this, if possible, as well ....
This is a big change @ressa for refactoring and clean-up.... we're going to feel much better once this is IN 😅
Comment #7
dydave commentedRE: The field description and label:
What does this field do?
Technical explanation:
There are 2 scripts to handle the hover menu animation to unfold the menu items:
1 - Default: is custom JS produced by and for the admin_toolbar module:
Standalone script: https://git.drupalcode.org/project/admin_toolbar/-/blob/3.x/js/admin_too...
Which doesn't require any external library to work ... just the usual Core libraries.
But this animation is a bit "dry" in the sense, the JS doesn't provide any feature on the time delay to hide the menu, to show, etc...
It's very basic and simple, the display and hide are just instantaneous.
2 - HoverIntent: is the JQuery HoverIntent plugin:
We've got a small piece of JS in the admin_toolbar module that builds on top of the JQuery plugin:
https://git.drupalcode.org/project/admin_toolbar/-/blob/3.x/js/admin_too...
See how it call the JS function
hoverIntent.See recent issue: #3513588: Update the jquery-hoverIntent JS library
Plugin URL: https://github.com/briancherne/jquery-hoverIntent
This is much more flexible, with a lot of parameters, see the demos here:
https://briancherne.github.io/jquery-hoverIntent/
Thus allowing to do nice things such as requested in child issue #3440852: Make un-hover delay configurable
But a lot more parameters "could" potentially be configurable.
I think it's very nice to have this feature in the module, but it needs to be a bit refactored currently, see my explanation in the IS.
Plus the wording of the field is not clear at all ....
So if you have any suggestions, they would surely be very welcome! 🙂
I definitely need help moving this ASAP please .... this is a big move that's going to unblock a lot of other tickets I've got lined up for a lot of improvements and code refactoring/clean-up.
As a heads up: We're going to move to Vanilla JS entirely and replace this JQuery plugin with its Vanilla JS equivalent: 🤫
https://github.com/svivian/sv-hover-intent-js
(We're following the Drupal Core trend ==> Moving away from JQuery 😅)
See the code example on that page for some of the parameters that "could" be configurable "out-of-the-box" 🥳
(without "too" much work)
This is coming tonight ... during my contrib time!
Please help!! 🙏
Comment #8
dydave commentedI've also got an answer line-up on the scroll issue, as well so I could get back to you on this ....
Just need a bit of time to put down everything in the ticket 😅
Comment #9
dydave commentedRE #7 for the checkbox field label:
Bear in mind this is going to show/unfold the other config fields which will be added in the child issue to make the "hoverIntent" parameters configurable ... so one or more fields will be added and visible there when the checkbox will be checked.
I've also changed the default behavior on install to use module's default JS standalone script.
In other words, currently, the default is JQuery hoverIntent and after this MR is merged, the default will be the simple standalone JS script.
(Only for new installs: Existing sites will keep their existing configuration, see the update hook in the MR)
The advanced hoverIntent animation will have to be selected by users specifically.
The reason for that is that the default shouldn't rely on an external JS plugin dependency.
If the script is not there or the dependency is not met for some reason....
By default, the module should be able to work fine without anything else (ie. its own script).
We should then be able to move out the JS plugin from the code base to a composer requirement (installed in libraries with composer) and I'll add checks on the settings form to check if the library is there for hoverIntent... if it's not there, we'll disable the checkbox and show some kind of warning or information message on the status report page, letting users know they can extend the module by installing the library manually if that's what they want.
Comment #10
ressaYou're welcome @dydave! Sounds good with the changes, a spring cleaning is sometimes needed :)
Here's what I do to set it up in Drupal 11 (Drush and Composer commands prepended with
ddevvia alias):Do I need to do more steps? Could it be because I am on Drupal 11?
Comment #11
dydave commentedLooks good @ressa!
Yes! It looks accurate .... not sure about D11 ... You're right... I haven't tested that ...
Try playing with the form options at
admin/config/user-interface/admin-toolbarCheck and uncheck, flush cache (just in case), and test the display of the menu... see if it works ....I'll give a round of tests again on a fresh D11 install as well...
If cache flushes need to be added, that's part of the changes to be added to the MR...
Try doing a bit more tests and report back ... I'll do the same this afternoon quickly... and ask some colleagues as well.
There's still some work needed indeed, with the checkbox label and description also.
oh .... and also check the console output and potentially the logs to see if any error or anything that could help fixing this could come up 🙂
So any feedback at all would be a great help!
Thanks in advance!
Comment #12
ressaThanks for explaining the thoughts and plans ahead for this in previous comments, and introducing JQuery HoverIntent (which I'll check it out later) They sound like great improvements!
I tried in Drupal 10 and Drupal 11 as well (both fresh installs) by checking out the Git branch:
... but I get the same result in both places, I tried checking and unchecking "Enable/Disable the hoverintent functionality", flushing cache, etc. but hovering does nothing. There are no errors in the Console.
It tried both Firefox and Chromium in Debian 12, if it makes any difference. But DDEV should make it irrelevant, I would think ...
Comment #13
dydave commentedThanks a lot @ressa!!
I'm going to give this a clean round of tests later today with a fresh D10 and D11 sites.
I'll definitely get back to you on this as soon as I have a bit of time.... I'm gonna be stuck in clients meetings this afternoon 😅 (joy!! 😅)
But I'll circle back on this ticket as soon as I am free 👌
Cheers! 🙂
Comment #14
ressaThanks @dydave, sounds good! Feel free to share any tips later on, how I can possibly do some simple debugging, or things to look out for -- then I can also look at this later today, since I'll also be away for now.
Comment #15
ressaI cracked the riddle: It's BigPipe! For some reason, hovering over "Extend" showed child menus all of a sudden, and looking at the source code, the only difference was a few BigPipe mentions. After uninstalling BigPipe everything works.
I think I understand why the hoverIntent plug-in cannot be used by default ... but it is a bit sad, since with the default settings, the menus will then fly out, when a user pass over the menu items, on the road to their destination. But perhaps that's a necessary situation? Maybe in the future, the "smooth" user experience can be made the default, somehow? I do know that some contrib modules, like Leaflet and Collapsiblock, simply bundle the JS library inside the module, to avoid loading external resource, and the module "just works". Is this not possible for Admin Toolbar as well?
Comment #16
dydave commentedThanks a lot @ressa!
Super helpful on all points! 🥳
Great job! That's super helpful and indeed, I generally disable
big_pipesince it currently sort of breaks the collapsible ondevel:dpmwith Symfony vardumper.So that's totally on point and I'm going to look into this ASAP.
First of all, I'm completely open to discussion and making different choices.
This has not been completely settled yet.
But, Technically speaking, I was brought to think this approach would be preferable because:
If we're looking at moving the hoverIntent plugin (whether Vanilla JS or JQuery) out of the code base, to be added as a dependency required in the
composer.jsonfile, we have to assume there might be cases where the dependency might not be met.See #3513588-16: Update the jquery-hoverIntent JS library:
In other words: Not all users may be using
composerto install the module and therefore might not have installed the hoverIntent plugin. In such cases, they would have to do it manually and place the file at a specific location, see for example the Colorbox module installation steps:https://git.drupalcode.org/project/colorbox/-/blob/2.1.x/README.md?ref_t...
Many other JS or JQuery related modules will have such kind of logic and also special messages displayed on the Status report page.
Additionally, any types of settings related with the missing libraries would be disabled to fallback on a default or even disabled state/files.
This is why I would "personally" suggest that we set the default behavior to the standalone admin_toolbar default vanilla JS behavior, without any external hoverIntent plugin.
But I'm open to anything really if you have better ideas in terms of UX: Let's try thinking a bit further:
If we set the hoverIntent library as the default, with the checkbox ticked by default, as it is currently on the Settings page, we could add an extra check upon display to check whether the file exists, in which case we would attach the plugin library, otherwise we would just fallback on the default..... something like that?!
In other words: if the plugin file doesn't exist, the default file would always be loaded.
+ Warning/Info message on the Status report page
+ Info message on Settings form + field disabled
Sure, no problem, that's also another option:
We should just not do this 😅 Moving the plugin out of the code base, see:
This is definitely not as straight forward as I would have thought....
I'm definitely open to suggestions @ressa 🙏
For the time being: We're going to keep the same logic as currently: hoverIntent plugin enabled by default (checked).
IF later we find a good way to move the plugin out of the code base and decide it is a better choice than keeping the file, then we will change the default value in the corresponding merge request 👌
I'm reverting this change for now!
I'm getting back to work on the MR... this will need more time to get reviewed and tested properly 👍
Thanks a lot!
Comment #17
dydave commentedComment #18
dydave commentedOK @ressa:
big_pipeissue by changing the JS libraries dependencies.enable_hoverintentcheckbox label and description to be a little bit clearer, but feel free to make suggestions:Sorry for the scope creep again, above at #16:
Changing the default value along with the way the plugin file is installed is definitely out-of-scope in this issue 😅
Tests are still passing 🟢 Back to Needs review 🤞
Feel free to let me know @ressa if you catch anything else, I would be glad to look into it as soon as possible.
Thanks again very much for the great help!
Comment #19
ressaAwesome @dydave, it looks and feels great! As a regular Admin Toolbar user, I can just download and install with the simplest of methods (when it's released) which is ideal, and not have to add an external library:
Thanks by the way for sharing how jQuery and JavaScript are currently working, and future plans for the module in a previous comment. SV-HoverIntent looks very nice, with great improvements like getting more available configuration options. Looking forward to this, eventually 🙂 ... I do hope the new SV-HoverIntent library will stay bundled inside Admin Toolbar as the old one, and not require Composer/NPM/Bower wizardry which is not very user friendly, in my opinion.
About the description, it is a difficult concept to explain in a few words ... but I found a great article Timing Guidelines for Exposing Hidden Content, got some inspiration, and tried to add a suggestion. What do you think?
PS. So great that the BigPipe thing got fixed! Though strange that it worked for your colleague, but maybe they disabled BigPipe as well? ... but shouldn't the tests fail? After my own experience of halting progress by using a "tampered" environment, I now attempt to use a freshly installed plain vanilla Drupal 11 for patch testing :)
Comment #20
dydave commentedSuper helpful feedback @ressa, once again! 🥳
Looks like we're doing some much needed clean-up here and I also don't really understand how the module could have worked with
big_pipebefore, without the correct dependencies to core JS libraries 😅.I think some of the clean-up work we've been doing and enforcing certain job validations is starting to pay off 👍
For example, raising the PHPSTAN validation level allowed me to catch a wrong test I was doing in the added code of the hook_update function, which I was able to modify in the last commit.
I've given a round of tests as well, locally, for the update function and it would seem to be working fine/as expected:
Moving the old config value to the new config.
The description you suggested is much clearer, thank you very much for taking the time to make it easier to understand for non tech-savvy users, that's a very difficult exercise 🙏
I've made the change to the merge request and the field should now display properly with the new cleaner description.
Let's keep in mind, this field might further evolve soon, when we start adding more hoverIntent config parameters, in particular in child issue: #3440852: Make un-hover delay configurable
So we should still be able to make more refinements to the field labels/descriptions in the future.
Lastly, concerning
big_pipe:I'm also very happy we could clean-up all this part properly:
All the JS files related with this feature:
admin_toolbar.hover.jsandadmin_toolbar.hoverintent.jswere moved to Vanilla JS as much as possible, with a single JQuery call to the hoverIntent plugin,
fixed all ESLINT validation errors as well and
wrapped in Drupal behaviors with calls to Core once, to ensure their code would only be executed once.
This started prompting errors and problems when enabling
big_pipe(calls toonce), which allowed identifying the libraries could be loaded in the wrong order due to missing dependencies.Concerning the Tests: I'm not sure, but I would tend to "think" PHPUNIT Tests don't necessarily run or enable the
big_pipemodule by default. Or maybe there could be other reasons as well...But this one is definitely a module that needs to be enabled when doing manual testing: I'll pay much more attention in the future.
Feel free to give the MR another round of review and let me know if you spot anything else 👌
Otherwise, I've done quite a bit of testing myself as well and think the changes should be pretty much ready to go.
Thanks again for all the great help! 🙏
Comment #21
dydave commentedOK, I think I understood this feature better yesterday:
In 3.5.3 and initially, I "think" what was initially planned for this feature is that the HoverIntent functionality would only be available if users enabled the
admin_toolbar_toolsmodule, see:https://git.drupalcode.org/project/admin_toolbar/-/blob/3.x/admin_toolba...
If the
admin_toolbar_toolsmodule is not installed, then its config setting (hoverintent_functionality) doesn't have any value and therefore loads by default the Basic hover JS behavior.So we would be modifying the initial logic by moving the setting out of the
admin_toolbar_toolsmodule, which should allow users to enable the HoverIntent setting just with theadmin_toolbarmodule enabled.Which I "personally" think is an improvement for the module, especially given your feedback on the smoothness and flexibility of the plugin.
The way this feature was initially implemented is quite confusing, because part of the logic went into admin_toobar and part went into admin_toolbar_tools.....
I "think" the way this feature was integrated to the module was to consider the HoverIntent as an "Extra" functionality, added by enabling the sub-module
admin_toolbar_tools.We have different options:
1 - Keep the current behavior and move the related logic from admin_toolbar to admin_toolbar tools (JS library, display logic in the admin_toolbar.module file), to have everything in one place.
2 - Change the existing behavior to allow admin_toolbar to fully control this setting (move the setting over to admin_toolbar).
Given the amount of tests and usage of this feature by users, we "should" be able to consider it should be stable enough to be moved to the "global" configuration of the module, and thus:
My preference would go to the option 2, which is currently implemented in the merge request: It would make sense to allow users to enable this feature without necessarily installing the admin_toolbar_tools module.
One thing would remain though if we wanted to be fully ISO with the previous logic: we would have to disable hoverintent by default, for users having only the admin_toolbar module installed after running DB updates.
In other words, users currently only running admin_toolbar and not admin_toolbar_tools, are using the standard Hover default behavior.
So after running the hook_update from this MR, the
enable_hoverintentsetting should be disabled and users would have to explicitly change the value in the form to select the hoverIntent behavior.That is ... only if we really want to be ISO with the current behavior.... this is also open to discussion and we could just go ahead and enable hoverintent by default for these users as well.
That's the only comment I had left on the MR, concerning the code here:
https://git.drupalcode.org/project/admin_toolbar/-/merge_requests/132/di...
Otherwise, new users installing admin_toolbar, would be using the HoverIntent plugin straight away (default setting, same as
admin_toolbar_tools).But it was important for me to fully clarify the change for this feature.
Thanks in advance for your feedback and comments!
Comment #22
ressaThanks for your thorough explanations of code, concepts and your deliberations in such detail, it's really great and helpful! And great that the refactoring of code can consolidate the hover-related code in a single place, for easier future maintenance.
About tests, I would also not be surprised if some test suites don't include BigPipe, due to potentially unforeseen issues ... So it's awesome that we're catching bugs, and oddities along the way, and getting better and more resilient testing in place, as a side effect.
And yes, eventually the config form for hoverIntent will have to be revisited, new features added and good wording found for labels and descriptions -- I am looking forward to getting started with this task, it will yield even more nice improvements :)
I have tried the new patch, and it works perfectly.
About the placement and enabling of hoverIntent, I never gave it another thought, since I always enable all the modules, i.e. the "main" Admin Toolbar, (
admin_toolbar) module as well as both sub-modules Tools (admin_toolbar_tools) and Search (admin_toolbar_search) -- and sub-module Tools gave me hoverIntent.I agree that moving hoverIntent from the sub-module Tools to the "main" Admin Toolbar module makes sense, which is your option #2.
About enabling hoverIntent or not for users who don't already have sub-module Tools enabled ... Seen from the perspective of "Who would not want this enabled, and what would be the reason?", my assumption is that the majority of users would want this feature, and I can't see strong reasons for not wanting this -- so I would vote for enabling hoverIntent by default, for all users.
Comment #23
dydave commentedAlright then @ressa! 🥳
Looks like we're all good then ! 👌
I've made the necessary code changes in the last commit, all jobs and tests are still passing 🟢
See commit: https://git.drupalcode.org/project/admin_toolbar/-/merge_requests/132/di...
Everything described in your comment above at #22 is now implemented in the merge request, in other words :
Users upgrading from the previous stable to the next will only have the HoverIntent feature disabled, if they specifically selected it to be disabled on the
admin_toolbar_toolsform, before running the upgrade.All other users, with only the admin_toolbar module enabled (admin_toolbar_tools disabled) or admin_toolbar + admin_toolbar_tools enabled (Enabled HoverIntent), will have the HoverIntent feature enabled.
I have just tested the upgrade with only admin_toobar enabled and after the last commit, it is working as expected:
HoverIntent enabled, after running DB updates.
Fresh installs will have it enabled by default.
I "think" we've really given all the different aspects a lot of thoughts and documented the different choices thoroughly in this issue 😅
Once again, I made all these changes because I believe your suggestions are worthy of interest and for the better good of the module. I completely agree with all your suggestions, orientations and choices ==> Let's keep moving forward! 🙂
The only reason I could see that users would not want to have HoverIntent enabled by default after upgrading (just the admin_toolbar), is maybe for performance reasons, since we would be adding a small JS file to be loaded.... but I'm not sure how impacting that could be 😅
Back to Needs review so you could take another look 👍
Thanks again so much for the great help !
Comment #24
ressaThis looks perfect @dydave, great work!
Like you, I also tried the new code, going from an existing Admin Toolbar 3.5.3 with hoverIntent disabled, and it stayed disabled after the database update. A fresh install of only Admin Toolbar gives the user hoverIntent enabled, as we agreed is the best default situation. Yes, a slight performance increase might be the result, but that's probably a tiny performance hit 🙂
And I agree, we have been around a lot of edges, and it looks good to go 🎉 Fantastic efforts here from you again, I am very grateful for that, and your openness to my suggestions. Have a nice day!
Comment #26
dydave commentedThanks a lot @ressa for the great help on this issue! 🥳
This is definitely a big one with a lot of code clean-up, in particular for the JS files with a rewrite of the hoverIntent feature with standard Drupal JS API and as little JQuery as possible, while fixing all ESLINT errors in these files.
After your confirmation, I sneaked in a last commit to fix a few minor ESLINT validation errors, see:
https://git.drupalcode.org/project/admin_toolbar/-/merge_requests/132/di...
Minor changes with indentation and line breaks.
I gave the module a last round of manual testing locally, with
big_pipeenabled and since all the tests were still passing 🟢 I went ahead and merged the changes above at #25 ! 🥳Let's get to the fun part now 😆
We should now be able to add extra config parameters for HoverIntent: #3440852: Make un-hover delay configurable
Thanks again very much for all the great help testing/reporting and super constructive advice on this issue @ressa! 🙏
Comment #27
ressaSo great to complete this, thanks @dydave! It's great that the code got cleaned up, and refreshed around the edges. Let's move on to the next task of adding extra config parameters for HoverIntent!
Comment #29
heddnI've opened #3528158: Missing config schema hoverintent_functionality to add config schema for this moved config.