Let the 'Transform dashes in URL to spaces in term name filter values' find terms that should contain the dash

Created on 8 May 2020, over 4 years ago
Updated 10 August 2023, over 1 year ago

Problem/Motivation

Follow up to #2710407: Option for 'Transform dashes in URL to spaces in term name filter values' on term arguments doesn't affect the query β†’

If you have a term "co-worker" and you enable 'Transform dashes in URL to spaces in term name filter values', no matches will be found because the dash will be removed.

So we need to figure out how to handle the case where you have both terms with spaces and terms with dashes, since now it only works with one or the other.

Also need to figure out how to handle this when you have both "co worker" and "co-worker" as terms.

Steps to Reproduce problem

Below step is for Drupal standard installation

  1. Create a term "co-worker" in the "Tags" vocabulary
  2. Now lets add a view to show "article" type contents
  3. Under the "ADVANCED" tab add a relationship Taxonomy term referenced from field_tags
  4. Click on Add and configure relationships. and then click on Apply
  5. Now under the "ADVANCED" tab add a Contextual Filter "Name" under "Taxonomy term" category.
  6. Click on Add and configure contextual filters
  7. Under WHEN THE FILTER VALUE IS NOT IN THE URL section, select Display contents of "No results found" option.
  8. Now check on Transform dashes in URL to spaces in term name filter values option.
  9. In the "WHEN THE FILTER VALUE IS IN THE URL OR A DEFAULT IS PROVIDED" section Check Specify validation criteria option and in the "Validator" dropdown select Taxonomy term name option.
  10. Click on Apply and Save the view.
  11. Now Under preview section type co-worker in the input box "Preview with contextual filters:" and click on "Update preview" button.
  12. You won't get any result

Proposed resolution

If the 'Transform dashes in URL to spaces in term name filter values' checkbox is set, search for terms that match either a space or a dash for any dashes in the argument value.

If multiple terms match, use the most recently created term.

Remaining tasks

  1. UX review of '#description' => $this->t('You can have both terms with spaces and terms with dashes like "co worker" and "co-worker". Then only the last created term will be matched.'),
    • Is that the behavior we want? Should it be "last" term, "first" term, other?
    • Is that description text good?
    • As per the Drupal Usability Meeting 2020-06-23 πŸ“Œ Drupal Usability Meeting 2020-06-23 Closed: outdated Update the description text to
      If there are terms with spaces and terms with dashes, like "co worker" and "co-worker", then only the last created term will be matched.
    • Also for reasons of backwards compatibility. Site builders have been dealing with the existing behavior for years, and expect that some sites have gone to a lot of trouble to work around the current behavior. It would be more comfortable with first trying the current behavior: for example, matching "co worker" but not "co-worker". If that fails, then look for matches with any combination of spaces and dashes.
  2. Other reviews / refinements.
  3. review below points has suggested

  4. RTBC.
  5. Commit.

User interface changes

Adds this description to the 'Transform dashes in URL to spaces in term name filter values' checkbox on the TermName views argument validator options form:

If there are terms with spaces and terms with dashes, like "co worker" and "co-worker", then only the last created term will be matched.

API changes

None.

Data model changes

None.

Release notes snippet

TBD.

✨ Feature request
Status

Needs work

Version

11.0 πŸ”₯

Component
ViewsΒ  β†’

Last updated about 2 hours ago

Created by

πŸ‡³πŸ‡±Netherlands Lendude Amsterdam

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

Comments & Activities

Not all content is available!

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

  • The Needs Review Queue Bot β†’ tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • πŸ‡ͺπŸ‡ΈSpain pcambra Asturies

    The patch here sort of works, but even if TermName.php loads the entity, the query by name will be broken as it will look the name *without* dash.

    Workaround for now is to use https://www.drupal.org/project/views_taxonomy_term_name_into_id β†’ + https://www.drupal.org/project/views_taxonomy_term_name_into_id/issues/3... ✨ Support term names containing spaces and dashes Needs work as pointed by @dww on #2

  • πŸ‡³πŸ‡¬Nigeria chike Nigeria

    Patch #43 is working for me in Drupal 9.

    Meanwhile having any special character like a bracket, asterisk, apostrophe, etc in the name will throw a WSOD.

  • πŸ‡³πŸ‡¬Nigeria chike Nigeria

    Attaching a related issue.

  • πŸ‡³πŸ‡¬Nigeria chike Nigeria

    Well looks like #43 has not gotten me out of this. I have a term 'color' and it has among its children 'color-code' and 'color-scheme' then I go on views page /color and it is showing /color-scheme once 'Transform dashes in URL to spaces in term name filter values' is turned on.

  • πŸ‡³πŸ‡¬Nigeria chike Nigeria

    Haha, I took off the patch, updated core to 9.5.10 and updated all modules (not sure if this counted). Then I fiddled with the view again and boom! all is working perfectly. All I did was reorder the contextual filters and with 'Transform dashes in URL to spaces in term name filter values' turned on, I am getting the desired results. No patches applied.

Production build 0.71.5 2024