Search results are showing up with numbers.

This is apparently because the search result output is an OL list. However, I don't think we want the numbers displayed. They were not displayed in D7.

Screen shot attached.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhodgdon’s picture

Actually, Stark has the same problem. Maybe we should solve this in a search.module CSS file?

BrightBold’s picture

Assigned: Unassigned » BrightBold
Issue summary: View changes
BrightBold’s picture

Component: Bartik theme » search.module
Status: Active » Needs review
FileSize
1.71 KB

Here's a stab at adding a Search CSS file that solves this problem cross-theme. This looks good to me but if it's wrong, please know that this is only my third patch (core or contrib) ever!

lokapujya’s picture

Patch applies and It removes the numbering from Bartik and Stark results.

Status: Needs review » Needs work

The last submitted patch, 3: search-results-styling-2115391-3.patch, failed testing.

BrightBold’s picture

I looked at this (my first experience with unit testing!) and I can clearly reproduce that adding the $variables['search_results']['#attached']['library'] in template_preprocess_search_results is somehow messing up $variables['help'], but I haven't yet figured out why. I will keep working on this.

lokapujya’s picture

Previously, search_results is empty when there are no results. But, now that we are adding the CSS file to the search_results array, search_results is not empty. Then, in the search-results.html.twig file, {% if search_results %} will always be true, and so will never get to the 'Your search yielded no results' part.

jhodgdon’s picture

Status: Needs work » Postponed
Related issues: +#1926344: Consolidate search-result.html.twig and search-results.html.twig

We are planning to remove search-results.html.twig in this other issue:
#1926344: Consolidate search-result.html.twig and search-results.html.twig
so we should probably postpone this issue.

BrightBold’s picture

@lokapujya — Thanks for the explanation. That makes sense.

jhodgdon’s picture

Status: Postponed » Needs work

The other issue is long-since resolved, so this one can be un-postponed now. Markup is different.

lokapujya’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 3: search-results-styling-2115391-3.patch, failed testing.

lokapujya’s picture

Where do we attach the CSS now that template_preprocess_search_results() is gone?

jhodgdon’s picture

RE #13, that is a very good question.

The search results page is built in \Drupal\search\Controller\SearchController::view(). It looks like in 8.x it is still possible to attach CSS file to a render array, so we should be able to put it in '#attached' as a library in $build['search_results'] or $build.

And looking at that previous patch... Libraries are not added with hook_library_info() any more, it looks like, but instead would go into a search.libraries.yml file. See change notice:
https://drupal.org/node/2201089
And it does look like making a library is the Drupal Way to attach CSS.

There is a CSS-only library YAML file example in core/modules/forum/forum.libraries.yml that should be useful to follow, although it looks like according to https://drupal.org/node/1887922 that we should put our CSS file into key "theme", not "component", since this is purely visual styling.

Hope that's enough to go on!

lokapujya’s picture

Status: Needs work » Needs review
FileSize
1.24 KB
2.43 KB

This adds CSS based on the D8 Change Record mentioned in #13.

jhodgdon’s picture

Title: Bartik displays numbers on search results » Numbers are displayed in search results list
Issue tags: +Regression
FileSize
14.6 KB
1.22 KB

This patch looked pretty good to me, but I tested it and it doesn't actually work.

I looked at some other uses of ['#attached']['library'] in Core and they look like this:

filter/filter.module:  $element['#attached']['library'][] = array('filter', 'drupal.filter');

while this patch had:

+    $build['#attached']['library'][] = 'search/drupal.search.results';

When I changed the string at the end to array('search', 'drupal.search.results'), then it worked.

Also, there is extra whitespace on the line just before that.

So... Here is a new patch -- no interdiff, this is a small patch and both of the lines in SearchController changed (all else is the same). And here are some before/after screen shots:
Before (taken when I first filed this issue):
search results with numbers
After (taken with different nodes in the DB with this new patch applied):
search results without numbers

longwave’s picture

@jhodgdon: Library references were changed very recently in #2203407: Replace #attached library array values with provider-namespaced strings, it looks like #15 is correct now to me?

jhodgdon’s picture

longwave: you're right. I forgot, I haven't done a pull on my repo recently. :(

OK, we need to skip the patch in #16 (I'll hide the file) and test the patch in #15 on a more recent install.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
1.21 KB

OK, now the patch in #15 works for me. It still has some trailing whitespace in the Controller section.

So here is a trivial redo of #15 without the extra spaces on that line. I will venture to go ahead and mark it RTBC since I have now verified that it works and longwave also looked at it.

The last submitted patch, 16: 2115391-no-numbers-16.patch, failed testing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 19: 2115391-no-numbers-19.patch, failed testing.

longwave’s picture

Status: Needs work » Needs review

19: 2115391-no-numbers-19.patch queued for re-testing.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC after random test failure.

webchick’s picture

Status: Reviewed & tested by the community » Needs work

This looks like a good fix, but according to CSS file organization (for Drupal 8) (assuming I'm reading that correctly) it should be in a search.theme.css, methinks. (If I'm wrong about that, please don't kill me, and re-mark RTBC! :D)

jhodgdon’s picture

I do not think that this applies when the CSS is included in a Library, which is what is done in this patch. We don't need that CSS file to be loaded on every page -- only on search results pages. Putting it in a library achieves that. I believe that if we put it into search.theme.css it would get loaded on every page.

This may not matter much, since there are only a few lines of CSS here... Maybe we can get someone involved in the theme system to comment?

star-szr’s picture

Assigned: BrightBold » Unassigned

Based on my reading of the CSS file organization docs I'd agree with @webchick that this should be added to search.theme.css.

LewisNyman’s picture

Assigned: Unassigned » amitaibu

The reason for the *.theme.css files is so it's easy to remove all non-essential CSS. I think the changes here definitely fall under non-essential. With that in mind the correct name could be search.theme.css.

jhodgdon’s picture

Thanks for clarifying! In that case, we should change the file name. The libraries thing is still necessary. Thanks!

zaporylie’s picture

Issue tags: +drupaldevdays

Hi, I'm new but I want to try fix file name issue

zaporylie’s picture

Status: Needs work » Needs review
FileSize
1.2 KB

I have changed the file name.

jhodgdon’s picture

Assigned: amitaibu » Unassigned
Status: Needs review » Reviewed & tested by the community

Thanks!

Confirmed this is exactly the same as the previous patch, with the file name change requested by webchick.

Also confirmed the patch works to remove the numbers on search results.

Let's get it in this time. :)

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Awesome, thanks!

Committed and pushed to 8.x.

  • Commit 1f9dbcb on 8.x by webchick:
    Issue #2115391 by jhodgdon, lokapujya, zaporylie, BrightBold: Numbers...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.