Problem/Motivation
Lazy is throwing the following fatal error on pages where the preprocessor is run, on an item that is not an (Media) Entity Reference.
Call to a member function getValue() on null in lazy_preprocess_field
Steps to reproduce
Enable the module and create a field with Lazy Loading enabled.
Now enter a SVG in that field, that is saved as an URL instead of a Media Item/Reference
Proposed resolution
We should check if the `#item` key in the preprocessor is available.
If not, we can assume that no target_id is available, so we can skip the processing.
Remaining tasks
Add an extra condition before using any #item values, like in the patch.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 3268604-9.patch | 829 bytes | staalex |
| #7 | lazy_preprocess_field.patch | 1.17 KB | jeffc518 |
| #2 | extra-item-condition.patch | 908 bytes | dennisdk |
Issue fork lazy-3268604
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
dennisdkComment #3
dennisdkComment #4
dennisdkComment #5
ndf commentedWe encounter this problem, because a custom image-processor is returning a render array without a referenced image, but with a plain uri instead.
Then additionally the lazy module allows to configure 'lazy load' on the field-display level.
IMO the patch is needed, because this lazy module should validate its input before further processing.
And if the input is not ok, it should fail silently.
Without this patch, it throws an unhandled exception. Which is inappropriate if a malformed image cannot be lazy-loaded.
But with this patch, the plain uri image is rendered, but not lazy loaded.
Comment #6
jeffc518 commentedI'm running into the exact same issue but with a "Remote Video" Media entity. Right before the error, it throws up a notice first:
Why does the patch create a new .module file though?
Comment #7
jeffc518 commentedRerolled patch to overwrite existing lazy.module (nested web root needed)
Comment #8
timme77 commentedpatch #7 works for me. thx!
Comment #9
staalex commentedPatch #7 works but it doesn't fix the initial problem. The problem appears when you are trying to lazy load SVGs. This can work if the SVGs are wrapped in an
<img>tag, but with this patch, they will simply be ignored. It's better to use $element['#items'] to load the file ID, which is the same even when we have ['#markup'] instead of the expected render array for files.Comment #10
_KurT_ commentedlooks like #9 is working
Comment #11
vensiresComment #12
firewaller commented#9 works for me
Comment #13
vensiresComment #16
liam morlandCreated merge request with the patch in #9.