Problem/Motivation
User story:
Given that I have a large number of options in a Views Jump Menu
As a user of the jump menu
I want to be able to search/filter the list of options
So that I can find the option that I am looking for.
It would be nice to be able to use the Views Jump Menu with the Chosen or Select2 JavaScript libraries.
More information:
- Chosen:
- Select2:
Proposed resolution
- Add a service to detect the presence of extra libraries which could be used to enhance the jump menu
- Add a control to the views_jump_menu format settings to let an administrator select an extra library; add an update hook to modify existing views_jump_menu configurations to add an (empty) extra library configuration option to ensure the config model is up-to-date
- Modify the theme code to detect if an extra library has been selected, and if so, attach that extra library to the render output
- Update tests to detect that extra libraries are output if selected
Remaining tasks
Write a patch- Review and feedback
- RTBC and feedback
- Commit
User interface changes
Adds an "Include extra library" control to the Views Jump Menu format settings if an extra library can be detected.
API changes
Adds a hook_views_jump_menu_extra_libraries_alter(&$extraLibrariesList) to allow modules/themes which define libraries to indicate that those libraries could be used with views_jump_menu.
Data model changes
Adds an extra_library string to the jump menu views schema, to track which extra library should be used with that jump menu.
Release notes snippet
Added optional support for extra JavaScript libraries to enhance the behavior of the jump menu.
Original report by jbfelix
Hello,
How to apply chosen or select2 library ?
Thanks
| Comment | File | Size | Author |
|---|---|---|---|
| #26 | 3077459-26--views_jump_menu--support-chosen-select2.patch | 23.52 KB | den tweed |
Comments
Comment #2
dbielke1986 commentedI need exactly the same...
Comment #3
hartsak commentedI was able to integrate a views jump menu with select2 by copying the modules/contrib/views_jump_menu/templates/views-jump-menu.html.twig file to my theme and modifying it a bit:
First attach the select2 library
{{ attach_library('select2/select2') }}Then modify the select element
Original code:
select-element with select2 support (you can add whatever options you need here):
I believe it would be possible to integrate a jump menu with the chosen library in a similar manner, but I have not tested it yet. Hope that helps you out with select2, though!
Comment #4
mparker17Updated issue summary
Comment #5
mparker17Here is a patch which adds support for the Chosen and Select2 modules (other modules can add their own support by implementing
hook_views_jump_menu_extra_libraries_alter()).To use it:
Comment #6
mparker17Found and fixed some coding standards issues.
Comment #7
mparker17I doubt this is the best solution, but here is a work-around for #3162684: Add a chosen/drupal.chosen.all library that also includes the CSS
Comment #8
colanThis looks fairly comprehensive, which is great. Would you be able to add the info in #5 to the README? I didn't do much of a code review, but noticed that the docs there weren't added anywhere.
Comment #9
mparker17Thanks for the feedback! Here's a new patch with an updated README. Additional feedback welcome!
Comment #10
colanNot sure if we need to be calling
\Drupalhere. Would it be possible to inject the service into the plugin as discussed at https://drupal.stackexchange.com/a/239868/2089, and then we can simply drop this method?I'm realizing that the info there should probably be added to the Dependency injection in Plugin (Block) doc page. (I just marked it as incomplete, and referred to the Drupal Answer.)
Should be combined into one line.
Comment #11
mparker17@colan, thanks for the code review!
Looks like I can inject the service!
However, I'd suggest leaving the method - from experience, I've found accessing dependencies through an accessor method to be more portable - the code can be agnostic about how dependencies are injected when overriding the class, copying code elsewhere, or mocking dependencies in tests.
Comment #12
colan👍
Comment #13
mparker17Here's a new patch. Reviews welcome!
Comment #14
colanCode looks good, and works well in my testing.
It actually didn't work right after setting it up, but then I came back to it later, and it did work. So a cache clear probably needed to happen.
Comment #15
mrpauldriver commentedA already have Select2 module installed and working for views exposed filters but I am struggling to get this working for views output.
I expect it is just a matter of not using the correct wrapper and select classes.
Could somebody put me on the right track please?
Comment #16
carolpettirossi commentedJust adding here that I tested patch provided on #13 and it works perfectly in my case (Chosen) with the DEV version.
However, the patch doesn't apply successfully to the beta3 version which forces me to use the DEV version. When should we expect a new release for this module?
Comment #17
mparker17@carolpettirossi, I've re-rolled the patch from #13 without tests as
3077459-17-on-beta3.do-not-test.patchso it'll apply to beta3.I'm not a maintainer so I can't create a new release. I believe the last person to create a release was @jcnventura
Since I made a mistake with the patch filename in #13 and I'm uploading a different patch file here for @carolpettirossi, I'm re-uploading the "real" patch from #13 as
3077459-17--views_jump_menu--support-chosen-select2.patchto (hopefully) avoid confusion about which patch is the most recent.There are no changes between the patch in #13 and
3077459-17--views_jump_menu--support-chosen-select2.patch, so I'm not uploading an interdiff, and I'm leaving the issue RTBC.@MrPaulDriver, I might be able to help; but first I need to know if you've applied the patch and then followed the steps in #5.
Comment #18
jcnventuraI think the fact that this is RTBCd helps a lot in the possible creation of a new release. I'd like to see an RTBC++, if possible before commtiting this.
Comment #19
replicaobscuraI have only tested this a small amount but have not come across any issues so far. I'll let at least one or two others hopefully confirm, then I think we are good to go anytime.
Comment #20
jcnventuraRe-roll of #17 for the current version.
Comment #21
jcnventuraAnd now with bytes in it.
Comment #22
jcnventuraAargh.. Previous patch included the patch from #17..
Comment #25
den tweed commentedRe-roll for 1.0 release
Comment #26
den tweed commentedPrevious patch didn't include the new files, fixed that