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.
Issue fork simple_parallax-3606149
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
Comment #2
o_timoshchuk commentedComment #3
o_timoshchuk commentedThe field formatter has been updated to avoid problems.
Comment #8
dkmishra commentedHi @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.
Comment #11
o_timoshchuk commentedComment #12
o_timoshchuk commentedI pushed changes, but in some rithon they do not appear here. I recreated the merge request.
Comment #13
o_timoshchuk commentedComment #14
dkmishra commentedHi @o_timoshchuk, thanks for the commits. The commit
bb2311586809d272d38e1c25c5bf1ae15eb458e3limits 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.
Comment #15
o_timoshchuk commentedComment #16
o_timoshchuk commentedThe field formatter was updated so that it only applies to image files.
Comment #17
dkmishra commentedHi @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
Comment #18
o_timoshchuk commentedComment #19
o_timoshchuk commentedMerged. Thanks, dkmishra, for helping with the issue