Problem/Motivation
The markup of the templates within the Search module currently does not follow Drupal coding standards.
See search-result.html.twig in the Search module folder and in Classy.
Proposed resolution
We need to improve the code to follow BEM standards.
For example:
.search-results .search-snippet-info {
should be improved to be...
.search-results__snippet-info {
and so on.
We then need to go find any CSS that uses the markup (in the module, in Seven and Bartik) and make sure the selectors are changed so we do not cause any regressions.
We made some progress within a Bartik issue before we realised that this needs to be cleaned up in Core first, see the work here... #2486441: Clean up the "Search results" component in Bartik.
Remaining tasks
Write a patch,
Review the patch - code.
Visual review the patch to check for NO regressions.
User interface changes
None.
Before


After


API changes
None
Beta phase evaluation
| Issue category | Task because it is a "be more in line with standards" change. |
|---|---|
| Issue priority | Just normal. |
| Unfrozen changes | Unfrozen because it only changes CSS and markup |
| Disruption | Will affect any contributed themes deriving from Classy that include CSS for search result items and do not have their own template file. Should not affect anything else. But, it brings our search result template classes more in line with our standards, so it should be done anyway. |
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | classy-after.png | 455.7 KB | cr0ss |
| #17 | bartik-after.png | 418.66 KB | cr0ss |
| #17 | classy-before.png | 464.01 KB | cr0ss |
| #17 | bartik-before.png | 416.1 KB | cr0ss |
| #11 | search-introducing-BEM-2489394-2.patch | 1.53 KB | cr0ss |
Comments
Comment #1
cr0ss commentedI'm working on this ticket right now.
Comment #2
cr0ss commentedDone with following:
Comment #5
cr0ss commentedThis ticket improves consistency and make search markup follow new drupal standarts and BEM.
No visual regression or changes as expected:
Before:
After:
Comment #6
cr0ss commentedComment #7
jhodgdonHm. So why is one of them changing to .search-result__title and the other to .search-result--snippet-info ? I don't understand the distinction.
Comment #8
cr0ss commentedjhodgdon, it's done to follow up BEM convention on naming elements.
.search-result - is a block
.search-result__title - is nested element of a block
.search-result__title--red - is a modified version of an nested element
Applying it to entire markup will make drupal 8 strongly consistent in terms of markup.
Comment #9
jhodgdonBut isn't the snippet info also a nested element?
Comment #10
star-szrYup!
These need to match up :) snippet-info is not a modifier I don't think.
Comment #11
cr0ss commentedYou are right, jhodgdon. Good catch, I've fixed a patch.
Comment #12
jhodgdonOK, this looks more self-consistent. So, a question about the standards:
search-result__snippet-info is a div within search-result. And within this, we have p tags for a snippet and an info line. So should those be search-result__snippet-info__snippet and search-result__snippet-info__info? Right now they are search-result__snippet and search-result__info. I just don't know what the standards are.
Comment #13
cr0ss commentedBy itself search-result__snippet-info__snippet or search-result__snippet-info__info is really descriptive, but in terms of understanding a component it's overtighten to a search block, where components are designed and should be independent entities. That's what I think, might be good point to asked BEM experts.
Comment #14
jhodgdonSo really snippet-info is "snippet and other info div". Within that, there is the snippet and the info line. I just don't know what the standards are.
Comment #15
cr0ss commentedSearch result is considered as block which is parent to elements. Where --info and --snippet are children as well it's not necessary when to be a children of --snippet-info element.
I.e, current state follows BEM standards and makes markup flexible enough to have:
for example. So we are keeping components flexible enough to be compatible with any search-result markup.
Comment #16
jhodgdonThat makes sense to me. In which case, the latest patch should be fine, but should we make new screen shots just in case (manual test)? The "After" shot above is not relevant any more.
Comment #17
cr0ss commentedHere we go.
Comment #18
jhodgdonGreat, thanks!
Fixed up beta eval in summary, which was there but not filled in.
Comment #19
star-szrhttps://www.drupal.org/node/1887918#sub-components seems like a good reference, for the record :)
+1 to RTBC.
Comment #21
xjmThanks for the reference to the standard and for the screenshots! Very helpful. I've embedded the latest screenshots in the summary. (It's always helpful to reviewers to do so.)
Note that, in general, we should also test CSS changes on RTL as well as LTR. (Reviewing the code carefully I think this is okay for RTL).
How I reviewed this:
This is the first change, replacing the expectation of a certain markup nesting with explicit styling. This makes total sense to me even without being very familiar with the standard, and it definitely is in line with the reference: https://www.drupal.org/node/1887918#sub-components
I grepped to confirm that (a) these were the only uses of
search-snippet-infoand (b) this wasn't inheriting any styling fromsearch-results. The only direct styling forsearch-resultsis onol.search-resultsand therefore not element to child items with the class.So this is the second change; instead of relying on
.item-list .titlefromsystem.theme.cssto make it bold, it adds a search-specific class to do that. I don't grok the standard that requires this entirely, but I'm trusting in @Cottser's signoff in addition to the RTBC. :)These are the third and fourth classes. I confirmed that there were no other uses of
search-infoorsearch-snippetoutside of the classes added in this template.I will say it's confusing that we have
search-result__info,search-result__snippet, andsearch-result__snippet-info, all as different things. But that naming confusion wasn't introduced here, so maybe a followup?This issue only changes user-facing strings, CSS, or markup, so per https://www.drupal.org/core/beta-changes, this can be completed any time during the Drupal 8 beta phase. Committed and pushed to 8.0.x. Thanks!
Comment #22
xjmComment #23
xjmOh, an aside @Cottser: I just added the following URL alias for that page:
https://www.drupal.org/coding-standards/css/architecture
Comment #24
star-szrThanks for the alias @xjm! Yes, change #2 threw me off but since it's Bartik it's to prevent any visual changes.
I'll create that follow up issue to discuss how we can improve the naming.
Comment #25
star-szrFollow-up is here: #2494665: Consider updating Classy's search result markup