Lack of access to swiper content white-screens the page with two errors

Created on 17 January 2025, about 1 month ago

Problem/Motivation

If I view an entity reference field that uses a swiper formatter for its output, but I do not have view access to the referenced entities, instead of empty field output I see a broken page with two errors in the log:

Warning: Undefined array key "field_name" in Drupal\swiper_formatter\Service\Swiper->renderSwiper() (line 215 of modules/contrib/swiper_formatter/src/Service/Swiper.php)

and

InvalidArgumentException: Field is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (line 616 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).

Steps to reproduce

1. Set up an entity reference field pointing at an entity type anonymous users do not have access to.
2. Set this field to display through a swiper formatter.
3. View the populated field as an admin and see the swiper.
4. View the populated field as an anonymous user and see the two errors bring down the page.

Proposed resolution

Handle lack of content due to no access to the content by returning empty instead of errors.

Remaining tasks

MR + review.

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States chrisolof

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @chrisolof
  • πŸ‡·πŸ‡΄Romania bbu23

    Hi @chrisolof,

    Thanks for reporting this issue, great catch!
    I'll investigate.

  • πŸ‡ΊπŸ‡ΈUnited States banoodle San Francisco, CA

    We are also seeing this issue, but in our case the referenced node entities are all published.

  • πŸ‡ΊπŸ‡ΈUnited States banoodle San Francisco, CA

    Ah, in our case, we are using the Domain module and Domain Microsite. I have realized this error only occurs when an anonymous visitor attempts to view a node with the node ref swiper on it from a Domain that the node is not affiliated with.

    The expected behavior in this case is a rendered site page (with header and footer) and a "you are not authorized to view this page" message.

Production build 0.71.5 2024