Problem/Motivation

As a sitebuilder, i want to use views grouping to have optgroups in the entityreference selection widget.

(Currently, entities are always grouped by bundle, not confiogurable.)

Proposed resolution

Add "group by field" option to views handler and use it in \Drupal\views\Plugin\EntityReferenceSelection\ViewsSelection::stripAdminAndAnchorTagsFromResults.

Remaining tasks

Update branch
Add test coverage
Code review

User interface changes

New option in views handler.

API changes

Probably none.

Data model changes

Probably none.

Release notes snippet

Views grouping is now available for the entityreference views selection handler.

Issue fork drupal-3193844

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

geek-merlin created an issue. See original summary.

geek-merlin’s picture

Status: Active » Needs review

Unfortunately the API won't let us do this gracefully, so i bent the bundle key to encode groupings. This works but i wish there'd be a better way.

Manually testes that 1 level of grouping works as expected. Having more grouping levels seems to cough,, but we can simply limit to one level here.

geek-merlin’s picture

Ignore this patch, only needed for comoser-patches.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

matthijs’s picture

I updated the patch to fix some issues regarding double encoded entities and unwanted line breaks (if you have twig debugging turned on).

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs tests

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

This will need test coverage. When the tests are added the branch should be updated for 10.1 please

nginex’s picture

StatusFileSize
new7.14 KB

Reroll for 9.5.x (also appliable for 10.1.x)

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

scotwith1t’s picture

No time to really evaluate more deeply, but a quick update that this doesn't seem to work as of Drupal 10.1.6.

matthijs changed the visibility of the branch 3193844-leverage-views-grouping-11.x to hidden.

matthijs’s picture

Status: Needs work » Needs review

Created a MR for 11.x, which also works for 10.4

matthijs changed the visibility of the branch 3193844-leverage-views-grouping-11.x to active.

matthijs changed the visibility of the branch 3193844-leverage-views-grouping to hidden.

smustgrave’s picture

Status: Needs review » Needs work

Moving to NW for the test coverage

r_h-l’s picture

This is an excellent and long overdue feature. Only thing I noticed is that in testing, the autocomplete widget seems to strip out the grouping. Any workaround?

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.