Add langcode from views filter to query metadata

Created on 14 June 2019, over 5 years ago
Updated 24 June 2023, over 1 year ago

With using the `domain access` module the `node access` functionality is used for checking permissions.
There is no problem with displaying a separate node. But any view does not display nodes in a language other than default.

Investigation showed that the `alterQuery` method in the `\core\modules\node\src\NodeGrantDatabaseStorage.php` method is responsible for the node's accessibility.

In order for the method to work correctly, the required language must be in the query metadata. For example, the "interface language" from the views filter. However, it is not in the query metadata.

I’m not completely sure that this task applies to the node or view module. Or maybe even domain access module. But once the code expects this parameter in the metadata, I created a patch that adds the language from the view filter.

📌 Task
Status

Needs work

Version

11.0 🔥

Component
Node system  →

Last updated 6 days ago

No maintainer
Created by

🇺🇊Ukraine Skymen

Live updates comments and jobs are added and updated live.
  • views

    Involves, uses, or integrates with views. In Drupal 8 core, use the “VDC” tag instead.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇊Ukraine Skymen

    Problem still present on Drupal 10.1.0 with Domain → 2.0.0-beta1 module. I've tested patch #14 and it works for me.

  • last update over 1 year ago
    Patch Failed to Apply
  • Ploblem still present on D10.1.1 with views_unpublish module.
    I create a patch for D10.1.1

  • last update over 1 year ago
    29,459 pass
  • 🇧🇪Belgium Wouter Waeytens

    Patch #26 fixed the issue for me.

  • 🇫🇮Finland vermario

    We encountered this same issue in the context of the module we are developing https://www.drupal.org/project/access_by_taxonomy →

    Our module adds grants that are based on the taxonomy terms added to a node (can be role or specific user). We add these grants also based on translation.

    The case where we see a problem in views (Compared to the actual access of the node when trying to visit it directly is this):

    1. we add a node with some restrictions, saying that it should be visible for a given user role, set the node as unpublished
    2. we add a translation to the node, publish the translation

    Now, all users of the role that is specified for access should see the node in views: in this case they should not see the original version, but they should see the translation.

    When doing an entity query or a view, the translation is not returned, because the table is checked with fallback = 1

    This is an example of the query:

    SELECT "node_field_data"."created" AS "node_field_data_created", "node_field_data"."nid" AS "nid", "node_field_data"."langcode" AS "node_field_data_langcode"
    FROM
    {node_field_data} "node_field_data"
    WHERE (("node_field_data"."type" IN ('article')) AND ("node_field_data"."langcode" IN ('it'))) AND (EXISTS (SELECT "na"."nid" AS "nid"
    FROM
    {node_access} "na"
    WHERE ((("gid" IN ('0')) AND ("realm" = 'all')) OR (("gid" IN ('2', '3')) AND ("realm" = 'access_by_taxonomy_role')) OR (("gid" IN ('4')) AND ("realm" = 'access_by_taxonomy_user')) OR (("gid" IN ('4')) AND ("realm" = 'access_by_taxonomy_own_unpublished')) OR (("gid" IN ('4')) AND ("realm" = 'access_by_taxonomy_owner'))) AND ("na"."grant_view" >= '1') AND ("na"."fallback" = '1') AND (([node_field_data].[nid] = [na].[nid]))))
    ORDER BY "node_field_data_created" DESC
    LIMIT 11 OFFSET 0

    The node_access table looks like this:

    10,en,1,1,access_by_taxonomy_view_any_article,1,0,0
    10,it,0,1,access_by_taxonomy_view_any_article,1,0,0
    10,en,1,3,access_by_taxonomy_owner,1,0,0
    10,it,0,3,access_by_taxonomy_owner,1,0,0
    10,en,1,3,access_by_taxonomy_own_unpublished,1,0,0
    10,it,0,3,access_by_taxonomy_role,1,0,0
    

    So there is no row with fallback = 1 that grants access, so the italian translation of the node is not shown in the view, even though the user would have access to it.

    Adding the patch has the opposite effect, both the unpublished node and the translation show up in the view, which is also what we don't wat.

    I wonder if we have found a corner case of the node_access system...

  • 🇧🇪Belgium jurgenr

    This patch causes issues on 10.3.*, due to the changes done in issue https://www.drupal.org/project/drupal/issues/1349080 🐛 node_access filters out accessible nodes when node is left joined Needs work .
    Is this patch still necessary?

  • I'm pretty sure it is still needed as I had to reroll it and use it - altough I'm using my own slightly expanded version of this https://git.drupalcode.org/project/drupal/-/merge_requests/1934/diffs which also covers relationships (I think, it was long time ago)... maybe the basic issue is resolved, I may test it some day.

    Meanwhile, here is the patch I'm using with 10.3 (no guarantees, it simply works for me) if anyone wants to try it.

Production build 0.71.5 2024