Allow the ProjectBrowser render element to control which sort options are shown

Created on 5 March 2025, 28 days ago

Problem/Motivation

Similar to [PP-1] Allow the ProjectBrowser render element to customize the available sort options Postponed , we want the ProjectBrowser render element to be able to control which sort options are exposed.

Proposed resolution

Introduce a #sort_options property to the render element. If provided, it should be an associative array like the one returned from ProjectBrowserSourceInterface::getSortOptions():

'#sort_options' => [
  'a_z' => $this->t('Alphabetical'),
  'z_a' => $this->t('Reverse alphabetical'),
];

Every key in the array needs to also be defined by getSortOptions() (using array_diff_key()), or we throw an exception. If it passes that bit of validation, then this is provided to the Project Browser instance settings' sorts property. This allows render element calling code to override the names of the sorts, but not their identifiers.

Meanwhile, on the frontend, we don't need to change much; all we have to do is hide the "Sort by" field if there are fewer than 2 sort options.

This should also be configurable for the Project Browser block -- for now, in a simple way, similar to the filters, where we just allow site admins to choose which sorts to show (as a set of checkboxes), but not influence their names or ordering.

Feature request
Status

Active

Version

2.0

Component

Code

Created by

🇺🇸United States phenaproxima Massachusetts

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

Merge Requests

Comments & Activities

  • Issue created by @phenaproxima
  • 🇺🇸United States phenaproxima Massachusetts
  • Pipeline finished with Failed
    28 days ago
    Total: 489s
    #441303
  • Pipeline finished with Failed
    28 days ago
    Total: 547s
    #441328
  • Pipeline finished with Failed
    28 days ago
    Total: 392s
    #441334
  • Pipeline finished with Success
    28 days ago
    Total: 466s
    #441345
  • Pipeline finished with Canceled
    28 days ago
    Total: 660s
    #441351
  • 🇺🇸United States phenaproxima Massachusetts
  • Pipeline finished with Failed
    28 days ago
    Total: 257s
    #441362
  • Pipeline finished with Failed
    28 days ago
    Total: 371s
    #441363
  • Pipeline finished with Success
    28 days ago
    Total: 857s
    #441371
  • 🇪🇸Spain penyaskito Seville 💃, Spain 🇪🇸, UTC+2 🇪🇺

    Have zero comments on the code. Looks perfect.
    Test coverage it's great too.

    TBH I don't feel like the block should be able to allow to override the sort labels. Nice that the API provides this though.

    A screenshot of 2 PB blocks, one with only ony sorting enabled (so no sort exposed), another one with only 2 sort options enabled:

    A screenshot of the validation error after selecting as default a sorting that is not enabled:

    The errored field is not highlighted, but has the "has-error" class. So this is a problem with off-canvas styling, not the field error handling here.

  • Pipeline finished with Canceled
    27 days ago
    Total: 36s
    #442089
  • 🇺🇸United States tim.plunkett Philadelphia

    Saving credit

  • Pipeline finished with Skipped
    27 days ago
    #442092
  • 🇺🇸United States tim.plunkett Philadelphia

    Merged !776 🎉

  • Pipeline finished with Failed
    27 days ago
    Total: 373s
    #442090
  • Pipeline finished with Failed
    21 days ago
    Total: 1212s
    #447258
  • Pipeline finished with Failed
    21 days ago
    Total: 1630s
    #447277
  • Pipeline finished with Failed
    20 days ago
    Total: 1394s
    #447326
  • Pipeline finished with Failed
    20 days ago
    Total: 1355s
    #447346
  • Pipeline finished with Failed
    20 days ago
    Total: 1484s
    #447377
  • Pipeline finished with Failed
    20 days ago
    Total: 1550s
    #447396
  • Pipeline finished with Canceled
    20 days ago
    Total: 1363s
    #447445
  • Pipeline finished with Failed
    20 days ago
    Total: 1429s
    #447469
  • Pipeline finished with Success
    20 days ago
    Total: 1548s
    #447489
  • Pipeline finished with Success
    20 days ago
    Total: 1293s
    #447634
  • Pipeline finished with Failed
    20 days ago
    Total: 2813s
    #447657
  • Pipeline finished with Failed
    20 days ago
    Total: 1437s
    #447718
  • Pipeline finished with Failed
    20 days ago
    Total: 1516s
    #447754
  • Pipeline finished with Failed
    20 days ago
    Total: 2551s
    #447767
  • Pipeline finished with Failed
    20 days ago
    Total: 1808s
    #447804
  • Pipeline finished with Skipped
    20 days ago
    #447825
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024