Problem/Motivation

The Simple Parallax formatter declares support for all entity_reference fields. Entity reference fields can point to nodes, taxonomy terms, users, and other entity types that do not implement getFileUri(), so selecting this formatter for those fields can cause a fatal error when the entity is viewed.

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "media_type" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 139 of /var/www/html/xxxxxx/web/core/lib/Drupal/Core/Entity/EntityTypeManager.php).

Steps to reproduce

1. Enable Simple Parallax JS in a Drupal 11.x setup.
2. Add an entity reference field that references content, taxonomy terms, or
another non-file/non-media entity type.
3. Configure the field display to use the Simple Parallax formatter.
4. Create content with a referenced entity.
5. View the rendered entity.

Expected

The formatter is only available for supported image/file/media references, or it handles unsupported referenced entity types without a fatal error.

Actual

The formatter can call getFileUri() on a non-file entity and fail during rendering.

Proposed resolution

Restrict the formatter to image fields and supported media/file references, or add type checks in viewElements() and skip/handle unsupported referenced entities safely. Add coverage for a non-media entity reference field display.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

dkmishra created an issue. See original summary.

o_timoshchuk’s picture

Assigned: Unassigned » o_timoshchuk
o_timoshchuk’s picture

Assigned: o_timoshchuk » Unassigned
Status: Active » Needs review

The field formatter has been updated to avoid problems.

grask0 changed the visibility of the branch 3606149-formatter-is-available to hidden.

grask0 changed the visibility of the branch 3606149-formatter-is-available to hidden.

dkmishra’s picture

Hi @o_timoshchuk, I don't see any commits in the 3606149-formatter-is-available branch for this issue yet, and the issue still persists. Please let me know if I'm missing something or doing anything wrong.

o_timoshchuk changed the visibility of the branch 3606149-formatter-is-available to active.

o_timoshchuk’s picture

Assigned: Unassigned » o_timoshchuk
o_timoshchuk’s picture

I pushed changes, but in some rithon they do not appear here. I recreated the merge request.

o_timoshchuk’s picture

Assigned: o_timoshchuk » Unassigned
dkmishra’s picture

Status: Needs review » Needs work

Hi @o_timoshchuk, thanks for the commits. The commit bb2311586809d272d38e1c25c5bf1ae15eb458e3 limits entity reference support to media references, which fixes the original fatal for node/term/user references. However, it still makes the formatter available for media reference fields that allow non-image media. In those cases the formatter cannot render meaningful output and may show only the field label, or produce invalid image output for file-like media. The applicability logic should be narrowed further, or the formatter should fail closed for non-image media in a way that does not expose it for unsupported field displays.

You can reproduce with a media reference field that allows non-image media.

1. Enable core Media and a non-image media type, for example Document or Remote video.
2. Add an entity reference field to a content type:
- Field type: Reference
- Target type: Media
- Allowed media types: include Document or Remote video

3. Create a media item of that type.
4. Create content using that media item in the media reference field.
5. Go to the content type’s display settings.
6. Set that media reference field’s formatter to Simple Parallax.
7. View the content.

At node view page it is showing only label of the field.

o_timoshchuk’s picture

Assigned: Unassigned » o_timoshchuk
o_timoshchuk’s picture

Assigned: o_timoshchuk » Unassigned
Status: Needs work » Needs review

The field formatter was updated so that it only applies to image files.

dkmishra’s picture

Hi @o_timoshchuk,

I tested the changes with commit `8bf57a7aba8d6a904987de5e8581efd3121f8524`, and everything is working fine now. The Simple Parallax formatter now appears only for image fields, as expected.

Thank you for the fix!
RTBC +1

o_timoshchuk’s picture

Status: Needs review » Reviewed & tested by the community
o_timoshchuk’s picture

Status: Reviewed & tested by the community » Fixed

Merged. Thanks, dkmishra, for helping with the issue

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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