Problem/Motivation

Discovered in #2860097: Ensure that content translations can be moderated independently.

This is cannot be currently reproduced via the UI, however node links break when rendering a pending revision adding a new translation. This happens because the #lazy_builder entry does not include the revision ID, so when loading the entity to actually render links, the default revision is loaded instead of the pending revision. In that case the default revision does not have the specified language and an exception is thrown.

Proposed resolution

Make sure the correct revision is loaded while rendering links.

Remaining tasks

  • Validate the proposed solution
  • Write a patch
  • Reviews

User interface changes

None

API changes

None

Data model changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

plach created an issue. See original summary.

plach’s picture

plach’s picture

plach’s picture

Title: Node links break when rendering a pending revision adding a new translation » Node links always load the default revision during rendering

Better title

The last submitted patch, 2: node-new_revision_translation_render-2939742-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Wim Leers’s picture

Status: Needs review » Needs work
Issue tags: +blocker

This blocks #2860097: Ensure that content translations can be moderated independently.

This happens because the #lazy_builder entry does not include the revision ID

I love how #lazy_builder makes the inputs EXPLICIT, which is why it's simple to explain and fix :)

+++ b/core/modules/node/src/NodeViewBuilder.php
@@ -89,7 +92,10 @@ public static function renderLinks($node_entity_id, $view_mode, $langcode, $is_i
+      $storage = \Drupal::entityTypeManager()->getStorage('node');

We can replace this with $this->entityManager->getStorage().

(This is a service injected into the parent class.)

Wim Leers’s picture

I tried running the test without the code changes, and … it still passed. We need a failing test-only patch.

Also reviewed the test coverage, found only nits:

  1. +++ b/core/modules/node/tests/src/Kernel/NodeViewBuilderTest.php
    @@ -0,0 +1,104 @@
    +   * Modules to enable.
    

    Nit: Just {@inheritdoc}.

  2. +++ b/core/modules/node/tests/src/Kernel/NodeViewBuilderTest.php
    @@ -0,0 +1,104 @@
    +    // Create the node bundles required for testing.
    

    Nit: Seems extraneous to mention?

  3. +++ b/core/modules/node/tests/src/Kernel/NodeViewBuilderTest.php
    @@ -0,0 +1,104 @@
    +    $output = $this->renderer->renderPlain($build)->__toString();
    

    Nit: I think (string) is cleaner — and we use that in most tests.

plach’s picture

plach’s picture

plach’s picture

Geez, uploaded the wrong patch, sorry :(

plach’s picture

Status: Needs work » Needs review
plach’s picture

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

Assuming the test-only patch fails, this is ready. The actual code changes are beautifully simple!

Status: Reviewed & tested by the community » Needs work
plach’s picture

Status: Needs work » Reviewed & tested by the community

There are 4 failures in HEAD common to both patches, but the test-only patch has also a failure in the new test. Based on that, restoring RTBC. This should be green/red as expected, as soon as HEAD is fixed.

Status: Reviewed & tested by the community » Needs work
Wim Leers’s picture

Status: Needs work » Reviewed & tested by the community

Only failed because #12 has the failing test-only patch after the passing fix+tests patch.

effulgentsia’s picture

Looks great. Adding reviewer credit.

  • effulgentsia committed f9365a0 on 8.6.x
    Issue #2939742 by plach, Wim Leers: Node links always load the default...

  • effulgentsia committed 4aab62a on 8.5.x
    Issue #2939742 by plach, Wim Leers: Node links always load the default...
effulgentsia’s picture

Version: 8.6.x-dev » 8.5.x-dev

Pushed to 8.6.x and 8.5.x.

effulgentsia’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

quietone credited Gribnif.

quietone’s picture