Add canonical site filter support for Views

Adds QueryableCanonicalSiteInterface, extending QueryableSiteInterface with canonicalQueryAlter(). Site plugins implementing it can restrict Views results to entities for which the site is the canonical (source) site, instead of any site the entity happens to be related to.

The "Sites" views filter (Drupal\sites\Plugin\views\filter\Sites) gains an optional "Canonical only" exposed checkbox, controlled via a new "Expose canonical site checkbox" option with its own hide-if-not-default/hide-if-single visibility settings. SitesContentSql::doQueryAlter() now calls canonicalQueryAlter() instead of queryAlter() for sites implementing QueryableCanonicalSiteInterface when that checkbox is active.

Also:

  • Adds a views.filter.sites config schema, required for the filter's new options to be exportable/importable.
  • Reworks access()/valueForm() on the Sites filter to account for the new canonical visibility alongside the existing site-selector visibility.
  • Fixes init() to handle the "_none" option correctly when $options['value'] is not yet an array.

This is a prerequisite for sites_group's GroupSitesBase to implement QueryableCanonicalSiteInterface, see https://www.drupal.org/project/sites_group/issues/3595527.

Merge request reports

Loading