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

Created on 17 January 2025, 5 days 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

Production build 0.71.5 2024