References to other entities being previewed don't display

Created on 17 October 2024, 29 days ago

Problem/Motivation

If a page being previewed contains references to other unpublished pages which have been added to the preview link they don't display. This creates a problem navigating between pages that have been included in a preview link. For example, if you have a site section that contains references to other pages in the section, the links to these pages won't display.

There's a further discussion of this problem here: https://github.com/localgovdrupal/localgov/issues/771

Steps to reproduce

  • Add an entity reference field referencing content to a content type.
  • Create a couple of unpublished nodes.
  • Create another unpublished node and add references to the previously created nodes.
  • Create a preview link for the node and add the other nodes to it.
  • View the preview link as an anonymous user. The links to the referenced content don't display even though they've been added to the preview link.

Proposed resolution

It appears the access check only runs for the current entity, so entities included in the preview link aren't checked and, as they are unpublished, access is denied.

The line of coding doing this check is: https://git.drupalcode.org/project/preview_link/-/blob/2.1.x/src/Preview...

Remove the `$route_entity->id() === $entity->id()` condition from this line fixes this problem, but there's a danger this allows too much.

The question I have is should the check load all preview entities and check these or is it okay to relax this condition?

Remaining tasks

  • Decide on how best to amend the access check condition.
  • Patch it

User interface changes

None

API changes

None

Data model changes

None

🐛 Bug report
Status

Active

Version

2.2

Component

Code

Created by

🇬🇧United Kingdom stephen-cox

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