Move language node access logic into NodeAccessController

Created on 27 March 2013, about 12 years ago
Updated 18 March 2025, 17 days ago

Follow up for #1658846-199: Add language support to node access grants and records β†’

Problem/Motivation

Logic in the wrong class.

Proposed resolution

Move into NodeAccessController

+++ b/core/modules/node/node.module
@@ -2522,6 +2522,18 @@ function node_access($op, $node, $account = NULL, $langcode = NULL) {
+    // If the Language module is enabled, try to use the language from
+    // content negotiation.
+    if (module_exists('language')) {
+      // Load languages the node exists in.
+      $node_translations = $node->getTranslationLanguages();
+      // Load the language from content negotiation.
+      $content_negotiation_langcode = language(LANGUAGE_TYPE_CONTENT)->langcode;
+      // If there is a translation available, use it.
+      if (isset($node_translations[$content_negotiation_langcode])) {
+        $langcode = $content_negotiation_langcode;
+      }
+    }

Remaining tasks

TBD

User interface changes

No UI changes.

API changes

TBD.

Original report by @effulgentsia in #1658846-199: Add language support to node access grants and records β†’

Posted by effulgentsia on March 22, 2013 at 7:06pm

+++ b/core/modules/node/node.module
@@ -2522,6 +2522,18 @@ function node_access($op, $node, $account = NULL, $langcode = NULL) {
+    // If the Language module is enabled, try to use the language from
+    // content negotiation.
+    if (module_exists('language')) {
+      // Load languages the node exists in.
+      $node_translations = $node->getTranslationLanguages();
+      // Load the language from content negotiation.
+      $content_negotiation_langcode = language(LANGUAGE_TYPE_CONTENT)->langcode;
+      // If there is a translation available, use it.
+      if (isset($node_translations[$content_negotiation_langcode])) {
+        $langcode = $content_negotiation_langcode;
+      }
+    }

This logic probably should be moved into NodeAccessController, but didn't do so in #198 in order to keep that a straight reroll. I think that can be follow up material though, unless someone is inspired to do it here.

πŸ“Œ Task
Status

Closed: outdated

Version

11.0 πŸ”₯

Component

node system

Created by

πŸ‡ΊπŸ‡ΈUnited States yesct

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

    (Drupal 8 Multilingual Initiative) is the tag used by the multilingual initiative to mark core issues (and some contributed module issues). For versions other than Drupal 8, use the i18n (Internationalization) tag on issues which involve or affect multilingual / multinational support. That is preferred over Translation.

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.

Production build 0.71.5 2024