Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
It's a fairly common use case to have A-Z lists filterable, e.g. on http://d8.thegalleryguide.co.uk/galleries/a-z/a
A natural user expectation would be for the filter to match the sort, by making the natural sort value available as a contextual filter.
That way, when setting up this kind of glossary view, items like "The Agency" would appear under "A" rather than "T"
Comment | File | Size | Author |
---|
Issue fork views_natural_sort-2832868
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 #2
generalredneckThat's an intesting scenario. You try it with exposed filters? In the filter use the starting with operation and expose the value. Then you should be able to at the very least use the query string to achieve what you want. I'be never tried to accomplish your scenario in core with normal sorting before.
Comment #3
malcomio CreditAttribution: malcomio at Capgemini commentedOn the D6 version of the site, I added an extra computed field for the "sort title", and used glossary mode on that as an argument: http://thegalleryguide.co.uk/galleries/a-z/a
I think for D8, it'll be necessary to create a filter and/or argument plugin in views_natural_sort to make it available as a filter, won't it?
Comment #4
generalredneckYeah. Would be a new filter plugin to do that. As for glossary... I do have a ticket for glossary support in d7. That will be something to port to d8 as well.
Comment #5
generalredneckReferencing Duplicate #2081751: Can't refer to views_natural_sort table in context filters glossary mode. This is for D7... but same feature.
Comment #6
malcomio CreditAttribution: malcomio as a volunteer commentedI couldn't get my head around how to implement a new argument plugin, so I ended up achieving this with a views_query_alter implementation on a view where I was setting glossary mode on the title. It feels a little bit hacky, but it gets the job done.
Comment #7
SurajHo CreditAttribution: SurajHo commentedTo refer to comment #4/#5 concerning the D7 ticket for glossary support, that is actually already possible. What I did in D7, was use the field Node: Title - Natural and exclude from display, and use that field as a contextual filter. Works perfectly.
Would it be possible to implement that same field in the D8 version? Because I would also like to do this in D8 :-)
Comment #8
leeksoup CreditAttribution: leeksoup as a volunteer commentedI'm trying to get contextual filters to work with natural sort on my site as well. It used to work years ago, as reported by SurajHo in #7, but the "Node: Title - Natural" field is now gone.
Can you give me any pointers to get this feature working again? I have read the comments here and at the issue linked at #5 but have no idea how to proceed.
Comment #9
keiserjb CreditAttribution: keiserjb as a volunteer and commentedFrom what I can tell, Node: Title - Natural field existed in the 7.x-1.x version of the module. Not sure how to get that capability back.
Comment #10
leeksoup CreditAttribution: leeksoup as a volunteer commentedI tried comparing the code for that version with the current one. There are major changes throughout and I couldn't figure out what was the relevant part for the Node: Title - Natural field.
Comment #11
leeksoup CreditAttribution: leeksoup commentedI was able to work around this problem by defining a Computed Field to hold the "natural sort" version of the title. Obviously, this isn't a great solution since it involves calculating and storing the same info a second time. But it does work with contextual filters.
Comment #13
generalredneckOk yall,
I made some headway on this. Keep in mind that my solution requires the fix in #3356107: Natural sort does not work with text fields anymore.
You can see the difference between the 2 branches in the following diff.
I have committed a test view in there. I've enabled "Glossary mode" on my contextual filter and as you can see it uses the first character of the raw transformed data. Keep in mind that this doens't work well for "numbers" so that's something yall will want to contend with. You can see that "A" works well and exactly like yall expected.
I've added full access to all the VNS information using Views. You can list all the records in that table if you want, but really needed to do that in order to allow relationships to work which allows contextual filters. Give it some tests, let me know how it works for yall.