Problem/Motivation
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
- Create a term "co-worker" in the "
Tags
" vocabulary - Now lets add a view to show "article" type contents
- Under the "ADVANCED" tab add a relationship
Taxonomy term referenced from field_tags
- Click on
Add and configure relationships.
and then click onApply
- Now under the "ADVANCED" tab add a Contextual Filter "Name" under "Taxonomy term" category.
- Click on
Add and configure contextual filters
- Under
WHEN THE FILTER VALUE IS NOT IN THE URL
section, selectDisplay contents of "No results found"
option. - Now check on
Transform dashes in URL to spaces in term name filter values
option. - 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 selectTaxonomy term name
option. - Click on Apply and Save the view.
- Now Under preview section type
co-worker
in the input box "Preview with contextual filters:" and click on "Update preview" button. - 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
- 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 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.
- Other reviews / refinements.
- RTBC.
- Patch with the updated description as suggested in Drupal Usability Meeting 2020-06-23 meeting is #16
- Commit.
review below points has suggested
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.