Problem/Motivation

ViewsReferenceViewSelection (src/Plugin/EntityReferenceSelection/ViewsReferenceViewSelection.php) declares:

  @EntityReferenceSelection(                                                                                                              
    id = "viewsreference:view",                                                                                                           
    label = @Translation("ViewsReference selection"),                                                                                     
    group = "views",                                                                                                                      
    weight = 1                                                                                                                            
  )  

Drupal core's own Views selection handler, Drupal\views\Plugin\EntityReferenceSelection\ViewsSelection (id: views), is registered in the same group = "views", with weight = 0.

When any entity reference field is configured with the generic handler: views setting — which is the value stored for every field where an admin picks "Views: Filter by an entity reference view" (e.g. a taxonomy-term reference, a node reference, anything unrelated to this module's own viewsreference field type) — SelectionPluginManager::getPluginId() resolves it like this:

  public function getPluginId($target_type, $base_plugin_id) {                                                                            
    $selection_handler_groups = $this->getSelectionGroups($target_type);                                                                  
    uasort($selection_handler_groups[$base_plugin_id], ['Drupal\Component\Utility\SortArray', 'sortByWeightElement']);                    
    $plugin_id = array_key_last($selection_handler_groups[$base_plugin_id]);                                                              
    return $plugin_id;                                                                                                                    
  }  

It sorts all plugins sharing that group by weight and picks the highest one. Because viewsreference:view's weight (1) is higher than core's own views plugin (0), it wins — so any field configured to use core's Views selection handler silently gets ViewsReferenceViewSelection instantiated instead of ViewsSelection.

Since ViewsReferenceViewSelection extends DefaultSelection (not ViewsSelection), its buildConfigurationForm() renders the Default handler's bundle-restriction checkboxes instead of the "View used to select the entities" / "View arguments" fields. The field's stored config still correctly points at a view, but the admin UI never shows it, and the "Reference method" select shows "Views: Filter by an entity reference view" correctly selected while the settings below it are simply wrong — with no PHP errors, no watchdog entries, and nothing in the browser console. It looks like a JS/AJAX bug but is a pure server-side plugin-resolution collision.

Steps to reproduce

1. Enable core views and viewsreference.
2. Create any entity reference field targeting a non-view entity type (e.g. a taxonomy term reference on a user/node/etc.).
3. Set "Reference method" to "Views: Filter by an entity reference view", pick a view + display, save.
4. Reload the field's settings form (admin/.../fields/.../).
5. Expected: "View used to select the entities" shows the saved view/display, plus "View arguments".
6. Actual: the "Default" handler's vocabulary/bundle checkboxes are shown instead — no way to see or change the selected view via the UI.

Proposed resolution

Lower ViewsReferenceViewSelection's weight below core's (e.g. -1), so it never outranks Drupal\views\...\ViewsSelection in group-based fallback resolution:

  - *   weight = 1                                                                                                                        
  + *   weight = -1   
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

nnevill created an issue. See original summary.

nnevill’s picture

Status: Active » Needs review
nnevill’s picture

Issue summary: View changes
nnevill’s picture

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

  • scott_euser committed 796127ee on 8.x-2.x authored by nnevill
    fix: #3618223 ViewsReferenceViewSelection's weight in the shared "views...
scott_euser’s picture

Status: Needs review » Fixed

Thank you! Added test coverage, merged; will make a new release shortly

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.