Problem/Motivation

The select2 facet widget outputs the built render array directly. This skips the default facet wrapper markup.

Steps to reproduce

View the HTML Output of the provided widget, it lacks default markup and template suggestions.

User interface changes

Wrapper Markup is added

Issue fork select2-3179030

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

archnode created an issue. See original summary.

archnode’s picture

Status: Active » Needs review
StatusFileSize
new886 bytes

The provided patch alters the returned array to match the structure of other facet widgets.

johnnydarkko’s picture

Status: Needs review » Needs work

Patch looks good to me, but is it necessary? The problem that I see with this feature is that if it's applied to existing sites is that the change in the display may cause visual regressions. Would be nice if this patch applies default css so that the bullets are removed so that they match the way that standard select field facets are displayed.

weseze’s picture

Status: Needs work » Reviewed & tested by the community

Patch is absolutely necessary.

Without it, the facets wrapper never gets rendered and a big bart of the theme logic in facets is skipped. You can for example not use template overrides for facets, not use facet preprocessor implementations, ... because al of that is completely bypassed now.

I, for example, added a lot of custom logic on the facets wrapper twig file and none of that was working on the select2 facet. There was also no way of making it work, since there is no point of entry in the theme layer for select2 facets. It goes from a generic "block" template, straight to generic "form-items" templates...

IMO the possible visual regression should be documented in the release note rather than being "fixed".

idiaz.roncero’s picture

I also think this is necessary.

There are many configurations at the facet level (i.e: display the facet title, or display a message if empty results) whose logic is encapsulated on the facet theme (in facets-item-listing, to be more precise).

The fact that Select2 skips this wrapper and outputs directly the Select2 element is basically disabling a bunch of functionality of the original module and makes it harder to develop and maintain.

idiaz.roncero’s picture

Regarding johnnydarkko's comment:

The point here (i think) is that the original facets-item-list.html.twig template is making an assumption that the $items variable will always be populated with an iterable list of elements and therefore builds the most appropriate HTML element: a

    . This is facet's default behavior and it's ok for lists of links and checkboxes.

    In my opinion, this could be improved on the original module since many facets (like select2 or range sliders) will output something very different and making an HTML list for a single element (in our case, the select2 input) feels cumbersome and semantically wrong.

    However, there is a simple solution: use theem suggestions and create a facets-item-list--select2.html.twig with the following content

<div class="facets-widget- {{- facet.widget.type -}} ">
  {% if facet.widget.type %}
    {%- set attributes = attributes.addClass('item-list__' ~ facet.widget.type) %}
  {% endif %}
  {% if items or empty %}
    {%- if title is not empty -%}
      <h3>{{ title }}</h3>
    {%- endif -%}

    {%- if items -%}
      {{ items }}
    {%- else -%}
      {{- empty -}}
    {%- endif -%}
  {%- endif %}
</div>

hswong3i made their first commit to this issue’s fork.

herved’s picture

StatusFileSize
new882 bytes

Here's a patch from MR 6, latest commit (db2dffba), in case anyone else needs it.
Our setup enforces static patches and MR diffs are not allowed (as they can change unexpectedly).

chr.fritsch made their first commit to this issue’s fork.

chr.fritsch’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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