Trying to get property 'url' of non-object
bymayo opened this issue · 8 comments
We've updated to the latest version of the plugin and we're getting errors when trying to transform images using Retcon:
The Twig we're using to output Retcon is:
{% set size = size ?? 'text-lg' %}
{% set styles = [
['attr', ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'], { class: 'tracking-tighter font-medium leading-none mt-5 mb-5 | lg:mt-7 lg:mb-7' }, false],
['attr', 'h1', { class: 'text-2xl | md:text-3xl | xl:text-4xl' }, false],
['attr', 'h2', { class: 'text-2xl | md:text-3xl | xl:text-4xl' }, false],
['attr', 'h3', { class: 'text-lg | md:text-xl | xl:text-2xl' }, false],
['attr', 'h4', { class: 'text-md | md:text-lg | xl:text-xl' }, false],
['attr', 'h5', { class: 'text-md | md:text-lg' }, false],
['attr', 'h6', { class: 'text-md' }, false],
['attr', 'a', { class: 'text-primary-500 border-b border-primary-500 | hover:text-primary-600 hover:border-primary-600' }, false],
['attr', 'p', { class: 'mb-5 ' ~ (size is defined ? size : 'text-base | sm:text-md | lg:text-lg') }, false],
['attr', ['ul', 'ol'], { class: 'rich-list list-outside mb-8 text-md' }, false],
['attr', 'ul', { class: 'rich-list--primary list-disc pl-4' }, false],
['attr', 'ol', { class: 'rich-list--primary list-decimal pl-4' }, false],
['attr', 'li', { class: 'mb-2' }, false],
['attr', 'strong', { class: 'font-bold text-black' }],
['attr', 'figure', { class: 'mx-0 py-0' }, false],
['attr', 'img', { class: 'w-auto h-auto mx-auto mb-10 mt-10' }],
['attr', 'blockquote', { class: 'font-medium' }],
['inject', 'blockquote', '<span class="absolute top-0 left-0">"</span>'],
['inject', 'blockquote', '<span class="absolute bottom-0 right-0">"</span>'],
['attr', 'iframe[src*=loom]', { class: 'absolute top-0 left-0 w-full h-full' }, false],
['transform', 'noRatio'],
['autoAlt', true],
['lazy', 'img', 'js-lazy-load', 'src']
] %}
<div class="redactor {{ color ?? 'text-gray-800"' }}">
{{ content|retcon(styles) }}
</div>
And removing:
['transform', 'noRatio'],
['autoAlt', true],
['lazy', 'img', 'js-lazy-load', 'src']
Seems to resolve the issue
Craft CMS: 3.8.14
Retcon: 2.6.1
Imager X: v3.6.6
The problem seems to be that you're using Imager X's named transforms feature, which Retcon isn't compatible with yet. I'll look into adding support for that, but for the time being you'll have to use an inline transform, i.e. change
['transform', 'noRatio']
to this:
['transform', { width: 100, ... }]
@mmikkel Strange, this error has only appeared on the latest version though, and didn't error previously (The sites been live with this feature since April 2022)
But i'll change the transforms to not use named transforms.
@bymayo That is strange. Do you know which Retcon version you were running prior to installing 2.6.1?
Before:
Craft CMS: 3.7.41
Retcon: 2.4.2
Imager X: v3.5.8
After:
Craft CMS: 3.8.14
Retcon: 2.6.1
Imager X: v3.6.6
@bymayo Thanks for that info!
I can reproduce the same error on my end, even with those exact versions installed. Which isn't surprising, considering Retcon's transform filter was never built to support named Imager transforms (Retcon predates that feature by several years), and from looking at how it's all implemented I can't really see how it would've ever worked.
It's weird that the above exception has only surfaced for you now, though – I can't explain that.
@mmikkel Yeah maybe the transforms never worked - Haha, but the error didn't appear previously. But managed to resolve this by changing it to ['transform', { width: 100, ... }]
etc
@bymayo Yeah, that part is odd.
Anyway, thanks for pointing this out. Ideally Retcon should support named Imager transforms; if nothing else even a better/more helpful exception message would be an improvement.
I'll circle back to this ASAP, and will update this issue when I do.
Revisiting this, I realise I gave a poor answer to this initially.
Turns out that Retcon actually is compatible with Imager X named transforms (since 2.4.0). I just forgot!
The problem is that your named transform consists of multiple transforms (i.e. an array) – which means that multiple transforms are returned from Imager, which retconTransform
didn't account for.
I've just added some changes to the retconTransform
to avoid this problem in the future – going forward, whenever Imager returns multiple transforms, Retcon will simply use the first one.
That change will be in the next Retcon release.