DomainAccessCurrentAllFilter with value NO does not work

Created on 23 October 2024, 2 months ago

Drupal Version

10.3.5

Domain module version

2.0.0-beta2

Expected Behaviour

When setting up a views filter with DomainAccessCurrentAllFilter value 0, the generated query should show only entities which are NOT assigned to the current domain.

Actual Behaviour

The generated SQL query applies the same SQL as when the value is set to 1.

Steps to reproduce

Set up a view with Available on current domain: YES.

Generated view SQL:

SELECT DISTINCT "node_field_data"."nid" AS "nid"
FROM
{node_field_data} "node_field_data"
LEFT JOIN {node__field_domain_access} "node__field_domain_access" ON node_field_data.nid = node__field_domain_access.entity_id AND (node__field_domain_access.deleted = '0' AND node__field_domain_access.langcode = node_field_data.langcode)
LEFT JOIN {node__field_domain_all_affiliates} "node__field_domain_all_affiliates" ON node_field_data.nid = node__field_domain_all_affiliates.entity_id AND (node__field_domain_all_affiliates.deleted = '0' AND node__field_domain_all_affiliates.langcode = node_field_data.langcode)
WHERE ((node__field_domain_access.field_domain_access_target_id = 'mydomain' OR node__field_domain_all_affiliates.field_domain_all_affiliates_value = 1))
LIMIT 11 OFFSET 0

Set up a view with Available on current domain: NO.

Generated view SQL:

SELECT DISTINCT "node_field_data"."nid" AS "nid"
FROM
{node_field_data} "node_field_data"
LEFT JOIN {node__field_domain_access} "node__field_domain_access" ON node_field_data.nid = node__field_domain_access.entity_id AND (node__field_domain_access.deleted = '0' AND node__field_domain_access.langcode = node_field_data.langcode)
LEFT JOIN {node__field_domain_all_affiliates} "node__field_domain_all_affiliates" ON node_field_data.nid = node__field_domain_all_affiliates.entity_id AND (node__field_domain_all_affiliates.deleted = '0' AND node__field_domain_all_affiliates.langcode = node_field_data.langcode)
WHERE ((node__field_domain_access.field_domain_access_target_id = 'mydomain' OR node__field_domain_all_affiliates.field_domain_all_affiliates_value = 1))
LIMIT 11 OFFSET 0

Example view:

uuid: d2d8bd7e-50df-4ccb-b09b-7c4516844636
langcode: en
status: true
dependencies:
  config:
    - core.entity_view_mode.node.full
  module:
    - domain_access
    - node
    - user
id: test_view
label: 'Test View'
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
display:
  default:
    id: default
    display_title: Default
    display_plugin: default
    position: 0
    display_options:
      title: 'Available on domain'
      fields: {  }
      pager:
        type: mini
        options:
          offset: 0
          pagination_heading_level: h4
          items_per_page: 10
          total_pages: null
          id: 0
          tags:
            next: ››
            previous: ‹‹
          expose:
            items_per_page: false
            items_per_page_label: 'Items per page'
            items_per_page_options: '5, 10, 25, 50'
            items_per_page_options_all: false
            items_per_page_options_all_label: '- All -'
            offset: false
            offset_label: Offset
      exposed_form:
        type: basic
        options:
          submit_button: Apply
          reset_button: false
          reset_button_label: Reset
          exposed_sorts_label: 'Sort by'
          expose_sort_order: true
          sort_asc_label: Asc
          sort_desc_label: Desc
      access:
        type: perm
        options:
          perm: 'access content'
      cache:
        type: tag
        options: {  }
      empty: {  }
      sorts: {  }
      arguments: {  }
      filters:
        current_all:
          id: current_all
          table: node__field_domain_access
          field: current_all
          relationship: none
          group_type: group
          admin_label: ''
          plugin_id: domain_access_current_all_filter
          operator: '='
          value: '1'
          group: 1
          exposed: false
          expose:
            operator_id: ''
            label: ''
            description: ''
            use_operator: false
            operator: ''
            operator_limit_selection: false
            operator_list: {  }
            identifier: ''
            required: false
            remember: false
            multiple: false
            remember_roles:
              authenticated: authenticated
          is_grouped: false
          group_info:
            label: ''
            description: ''
            identifier: ''
            optional: true
            widget: select
            multiple: false
            remember: false
            default_group: All
            default_group_multiple: {  }
            group_items: {  }
      style:
        type: default
        options:
          grouping: {  }
          row_class: ''
          default_row_class: true
          uses_fields: false
      row:
        type: 'entity:node'
        options:
          relationship: none
          view_mode: full
      query:
        type: views_query
        options:
          query_comment: ''
          disable_sql_rewrite: false
          distinct: false
          replica: false
          query_tags: {  }
      relationships: {  }
      header: {  }
      footer: {  }
      display_extenders: {  }
    cache_metadata:
      max-age: -1
      contexts:
        - 'languages:language_interface'
        - url.query_args
        - url.site
        - 'user.node_grants:view'
        - user.permissions
      tags: {  }
  available:
    id: available
    display_title: Available
    display_plugin: block
    position: 1
    display_options:
      display_description: ''
      display_extenders: {  }
    cache_metadata:
      max-age: -1
      contexts:
        - 'languages:language_interface'
        - url.query_args
        - url.site
        - 'user.node_grants:view'
        - user.permissions
      tags: {  }
  not_available:
    id: not_available
    display_title: 'Not available'
    display_plugin: block
    position: 2
    display_options:
      title: 'NOT Available on domain'
      filters:
        current_all:
          id: current_all
          table: node__field_domain_access
          field: current_all
          relationship: none
          group_type: group
          admin_label: ''
          plugin_id: domain_access_current_all_filter
          operator: '='
          value: '0'
          group: 1
          exposed: false
          expose:
            operator_id: ''
            label: ''
            description: ''
            use_operator: false
            operator: ''
            operator_limit_selection: false
            operator_list: {  }
            identifier: ''
            required: false
            remember: false
            multiple: false
            remember_roles:
              authenticated: authenticated
          is_grouped: false
          group_info:
            label: ''
            description: ''
            identifier: ''
            optional: true
            widget: select
            multiple: false
            remember: false
            default_group: All
            default_group_multiple: {  }
            group_items: {  }
      filter_groups:
        operator: AND
        groups:
          1: AND
      defaults:
        title: false
        filters: false
        filter_groups: false
      display_description: ''
      display_extenders: {  }
    cache_metadata:
      max-age: -1
      contexts:
        - 'languages:language_interface'
        - url.query_args
        - url.site
        - 'user.node_grants:view'
        - user.permissions
      tags: {  }

The current operator code checks is_null on the value, so clearly this is the part which is wrong:

      if (is_null($this->value)) {
        $where = "(($real_field <> '$current_domain_id' OR $real_field IS NULL) AND ($all_field = 0 OR $all_field IS NULL))";
        if ($current_domain->isDefault()) {
          $where = "($real_field <> '$current_domain_id' AND ($all_field = 0 OR $all_field IS NULL))";
        }
      }
      else {
        $where = "($real_field = '$current_domain_id' OR $all_field = 1)";
        if ($current_domain->isDefault()) {
          $where = "(($real_field = '$current_domain_id' OR $real_field IS NULL) OR $all_field = 1)";
        }
      }
🐛 Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom mattjones86 🇬🇧 GMT+0

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024