Problem/Motivation

When used with autocomplete field, any view can be selected even the ones not select in preselect option, works well with the select list though.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

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

hansa11 created an issue. See original summary.

_shy’s picture

Status: Active » Needs review
StatusFileSize
new3.07 KB

Here is a patch to fix this issue. I added @EntityReferenceSelection plugin for support preselect options for the autocomplete field widget.

finex’s picture

Thank you, the patch works flawlessly.

scott_euser’s picture

Apologies for missing this. I am just a bit nervous that this is risky as it seems quite likely that there may be cases where site editors have selected a View they are not allowed to select according to 'Preselect View Options'. I suppose it won't break things BUT it would then prevent resave e.g. of a node or paragraph.

Beyond that we just need test coverage + conversion to merge request to get this in.

scott_euser’s picture

Status: Needs review » Needs work

Needs also coordination in case #2922687: Allow inclusion of views by administrative tag(s) in select widget. is merged first to also add that restriction to autocomplete (could also be a separate follow-up issue though)

trackleft2’s picture

It might be safer to move the configuration for this feature, to the field widget settings for the select widget. This approach would ensure that existing widgets (currently only the Select widget) continue to function properly while introducing this as a new option for the Autocomplete widget.

What are your thoughts?

scott_euser’s picture

Hmmm it's a good suggestion.

I guess my worry is that choosing which views are available is probably comparably essential as choosing a vocabulary with a taxonomy reference field and DX might suffer hiding it.

Might anyways be simpler to add support for autocomplete then to handle the update hooks.

trackleft2’s picture

I've added a proof of concept as Merge Request !82 for your consideration.

The merge request:
- Incorporates the patch from #2 but uses widget settings instead of field settings.
- Has an update function to move values from field config to field widget config
- Adds widget settings for both the select element and the autocomplete widget.

scott_euser’s picture

Hmmm yeah I see how it would work, and thank you for spending the time on it. I think its a fairly big DX change though and I still worry about it then being more hidden.

Are there other features you feel are specific to the Select widget that justify the separation of controls from autocomplete vs select? Otherwise I can try to insist that any future new feature covers both, allowing us to keep the settings in the field settings (e.g. in #2922687: Allow inclusion of views by administrative tag(s) in select widget.)

If we do ultimately go down this route, we can sign-post that more controls can be found in the manage form display, but let's not do that yet until we get more of a direction decision (which I am not convinced is needed yet). If we are at a stalemate I can reach out to other maintainers in Drupal Slack to get opinions. Sorry - just nervous as its a very heavily used module

For anyone else reviewing, updated screenshot:

Manage form display with proposed change:

Manage field settings with proposed change:

scott_euser’s picture

FWIW:

  1. I think for the sake of fixing the bug we should get autocomplete to match select like the patch in #2 starts but then also needs tests as per #4.
  2. Then we can move the wider DX change to a follow-up to deal with it in isolation from the bug.

trackleft2’s picture

I've converted the patch in #2 to a merge request.

This seems to work, however, now the existing PHPUnit tests are failing.

There was 1 failure:
1) Drupal\Tests\viewsreference\FunctionalJavascript\ViewsReferenceFieldTest::testCreateViewsReferenceField
Behat\Mink\Exception\ElementNotFoundException: Option with id|name|label|value "block_1" not found.
/builds/issue/viewsreference-3257767/web/core/tests/Drupal/Tests/WebAssert.php:240
/builds/issue/viewsreference-3257767/tests/src/FunctionalJavascript/ViewsReferenceFieldTest.php:107
ERRORS!
Tests: 15, Assertions: 141, Errors: 1, Failures: 1, Skipped: 1.

See https://git.drupalcode.org/project/viewsreference/-/blob/8.x-2.x/tests/s...

scott_euser’s picture

Status: Needs work » Needs review

Thanks for all the work on this! Fixed it up a bit + added new test coverage that fails before this code and passes after.

scott_euser changed the visibility of the branch 3257767-preselect-doesnt-work to hidden.

scott_euser’s picture

Hid the managed form display branch just to avoid future confusion (not delete of course in case ever revisiting UX).

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

scott_euser changed the visibility of the branch 8.x-2.x to hidden.

scott_euser’s picture

Running out of time this morning but hopefully that will resolve the test coverage. Could use a check from one of us here again to get an RTBC if so. Thanks!

scott_euser’s picture

Pipeline green now yeah

scott_euser’s picture

Status: Needs review » Fixed

Thanks for the back and forth on this. The DX change to manage form display can be a follow-up, will leave the branch in case its ever useful; but good to actually fix the issue itself here.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.