diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareCombinationTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareCombinationTest.php index 1ddad42..0459555 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareCombinationTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareCombinationTest.php @@ -227,6 +227,12 @@ function testNodeAccessLanguageAwareCombination() { $this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_no_language_private'], $this->web_user, 'ca'); $this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_no_language_private'], $this->web_user, 'en'); + // Access only for request with no language defined. + $this->assertNodeAccess($expected_node_access, $this->nodes['public_no_language_public'], $this->web_user); + $this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_no_language_public'], $this->web_user, 'hu'); + $this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_no_language_public'], $this->web_user, 'ca'); + $this->assertNodeAccess($expected_node_access_no_access, $this->nodes['public_no_language_public'], $this->web_user, 'en'); + // No access for all languages as both node access modules deny access. $this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_no_language_private'], $this->web_user); $this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_no_language_private'], $this->web_user, 'hu'); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareTest.php index f137d12..9344ec5 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageAwareTest.php @@ -177,6 +177,15 @@ function testNodeAccessLanguageAware() { $this->assertNodeAccess($expected_node_access_no_access, $this->nodes['no_language_private'], $this->web_user, 'ca'); $this->assertNodeAccess($expected_node_access_no_access, $this->nodes['no_language_private'], $this->web_user, 'en'); + // When no language is specified for a public node, access should be granted + // only for the existing language (not specified), so only the request with + // no language will give access, as this request will be made with the + // langcode of the node, which is "not specified". + $this->assertNodeAccess($expected_node_access, $this->nodes['no_language_public'], $this->web_user); + $this->assertNodeAccess($expected_node_access_no_access, $this->nodes['no_language_public'], $this->web_user, 'hu'); + $this->assertNodeAccess($expected_node_access_no_access, $this->nodes['no_language_public'], $this->web_user, 'ca'); + $this->assertNodeAccess($expected_node_access_no_access, $this->nodes['no_language_public'], $this->web_user, 'en'); + // Query the node table with the node access tag in several languages. // Query with no language specified. The fallback (hu) will be used. diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageTest.php index d259fe0..71b2b8a 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageTest.php @@ -87,6 +87,28 @@ function testNodeAccess() { // Tests that access is granted if requested with no language. $this->assertNodeAccess($expected_node_access, $node_public_no_language, $web_user); + // Tests that access is not granted if requested with Hungarian language. + $this->assertNodeAccess($expected_node_access_no_access, $node_public_no_language, $web_user, 'hu'); + + // There is no specific Catalan version of this node and Croatian is not + // even set up on the system in this scenario, so the user will not get + // access to these nodes. + $this->assertNodeAccess($expected_node_access_no_access, $node_public_no_language, $web_user, 'ca'); + $this->assertNodeAccess($expected_node_access_no_access, $node_public_no_language, $web_user, 'hr'); + + // Reset the node access cache and turn on our test node_access() code. + drupal_static_reset('node_access'); + \Drupal::state()->set('node_access_test_secret_catalan', 1); + + // Tests that access is granted if requested with no language. + $this->assertNodeAccess($expected_node_access, $node_public_no_language, $web_user); + + // Tests that Hungarian is still not accessible. + $this->assertNodeAccess($expected_node_access_no_access, $node_public_no_language, $web_user, 'hu'); + + // Tests that Catalan is still not accessible. + $this->assertNodeAccess($expected_node_access_no_access, $node_public_no_language, $web_user, 'ca'); + } /** diff --git a/core/modules/node/node.module b/core/modules/node/node.module index de06779..96b65e4 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1635,6 +1635,10 @@ function node_access($op, $node, $account = NULL, $langcode = NULL) { if ($langcode) { $node = $node->getTranslation($langcode); + // If the language could not be loaded, bail. + if ($node->language()->id !== $langcode) { + return FALSE; + } } return $access_controller->access($node, $op, $account); }