Make natural sort value available as a contextual filter

Created on 4 December 2016, almost 8 years ago
Updated 6 May 2024, 5 months ago

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"

✨ Feature request
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom malcomio

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • I'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.

  • πŸ‡ΊπŸ‡ΈUnited States keiserjb

    From 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.

  • I 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.

  • I 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.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update about 1 year ago
    1 fail
  • Status changed to Needs review about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States generalredneck

    Ok yall,

    I made some headway on this. Keep in mind that my solution requires the fix in πŸ› Natural sort does not work with text fields anymore Needs work .

    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.

  • πŸ‡ΊπŸ‡ΈUnited States plato1123

    Just curious if this has been implemented in any current release? I also am struggling with how to make this work as a contextual filter. Thanks!!

  • πŸ‡ΊπŸ‡ΈUnited States generalredneck

    Nope still hanging out here waiting for feedback. I'm taking a guess noone has tested my work. I'll come back to this at some point this quarter.

  • πŸ‡ΊπŸ‡ΈUnited States plato1123

    Ok, let me dig through your comments & code a little deeper and maybe I can provide some feedback. Thanks!

  • πŸ‡ΊπŸ‡ΈUnited States plato1123

    Apologies, is there a place I can pull the full code I need to test this or do I need to pull and then apply successive patches? Thanks!

  • πŸ‡ΊπŸ‡ΈUnited States generalredneck

    Everything is part of the merge request. You can get the patch or the full code from the links up above. If toy are using beta8 it appears the patch may not apply cleanly at the moment

  • πŸ‡ΊπŸ‡ΈUnited States generalredneck

    @plato1123
    I got this rerolled for you. See if you can give it a look now. Either check out/download the MR or pull in the latest dev release and apply the patch from the "plain diff" link above.

Production build 0.71.5 2024