The sites module's "Sites" Views filter (Drupal\sites\Plugin\views\filter\Sites) exposes a "Canonical only" option for sites whose plugin implements \Drupal\sites\QueryableCanonicalSiteInterface. This restricts a content listing to entities for which the given site is the canonical/source site, rather than any site the entity happens to be available on (which is what the existing queryAlter() / QueryableSiteInterface does).
GroupSitesBase currently implements QueryableSiteInterface::queryAlter() but not QueryableCanonicalSiteInterface, so the "Canonical only" option is unavailable for sites_group-based sites.
We have a local, uncommitted patch for this (patches/sites_group/canonical-site-filter.patch) that adds the interface and a canonicalQueryAlter() implementation, mirroring queryAlter() but with an additional is_source_site = 1 condition on the group_relationship_field_data join. This issue is to land that properly as a patch/MR against sites_group instead of carrying it as a local-only patch.
Proposed change
class GroupSitesBase extends SiteWithContentBase implements GroupSiteInterface, QueryableCanonicalSiteInterface { // ... /** * {@inheritdoc} */ public function canonicalQueryAlter(SelectInterface $query, EntityTypeInterface $entity_type) { if (!$plugin_ids = $this->sitesGroupService->getPluginIdsByEntityTypeId($entity_type->id())) { return; } $group_relationship_data_table = $this->entityTypeManager->getDefinition('group_relationship')->getDataTable(); $data_table = $entity_type->getDataTable(); $id_key = $entity_type->getKey('id'); $group_id = $this->getGroup()->id(); $query->join( $group_relationship_data_table, 'gr_site', "$data_table.$id_key = %alias.entity_id AND %alias.plugin_id IN (:plugin_ids[]) AND %alias.gid = :gr_site_gid_" . $group_id . " AND %alias.is_source_site = 1", [ ':plugin_ids[]' => $plugin_ids, ':gr_site_gid_' . $group_id => $group_id, ], ); } }
Prerequisite
Issue fork sites_group-3595527
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
Comment #2
hydra commentedComment #4
hydra commentedComment #6
hydra commented