craft-seomatic
craft-seomatic copied to clipboard
Aggregated data from matrix-field returns strange values
When we aggregate data from a matrix-field (richtext, redactor), the content that is shown in the frontend is not from the matrix-field, it seems to be craft-internal data from the entry. If no matrix-field is chosen for the content, everything works fine. If no matrix-field with text exists, only other matrix-fields that show images, etc. everything works fine. The broken content touches als "og:description" and "twitter:description" - all field that try to get the content from the same matrix-fields.
Screenshots
Versions
- Plugin version: 4.0.37
- Craft version: 4.5.11.1
In our discussions, you mentioned that you were unable to replicate this with a different project -- which is making me think this is something specific to your project.
Do you have any steps to reproduce that you can give me so I can attempt to replicate the bug, and fix it, if it is one?
Still checking if there is another project that's aggregating it's data in the same way. I'll come back to you as soon as I know. Maybe important: worked on craft 3, error showed up after update to 4.
I've tried replicating this by setting up a Matrix block with a plain text field and a rich text field in it.
Then I set SEOmatic to pull the description from that Matrix field, and everything worked as expected. It extracted the text from the Matrix fields, and used them for the description.
Can you help me out here with what could possibly be different with your setup for this site?
Are you seeing this behavior on any other sites you're using SEOmatic on?
So I think I'm going to need a composer.json
and db dump if I'm to attempt to diagnose this.
That or we do a video conf call:
https://savvycal.com/nystudio107/chat
okay yeah so likely something you're doing in your templates is affecting it, because I get the correct result using a generic index.twig
:
<title>🚧 Home | Rotax Aircraft Engines</title><meta name="generator" content="SEOmatic">
<meta name="keywords" content="technology, create, finding, continue, pushes, aviation, innovation, we’re, bursting, ever-better, built, boundaries, aircraft, engine, performance">
<meta name="description" content="We have built – and continue to create – technology that pushes the boundaries of aircraft engine performance to take the piloting experience to the next…">
<meta name="referrer" content="no-referrer-when-downgrade">
So if you could send me the templates/
directory on Discord, I could be able to figure it out pretty easily.
Okay so it ends up being that the issue is that in this case, the Matrix blocks were being eager loaded in the templates via something like this:
{% do craft.app.elements.eagerLoadElements(
className(entry),
[entry],
['groupedEntryIntro']
) %}
...and then in the helper/Text.php
class, it failed the is_array()
test that was there because as of Craft 4, eager loaded elements return a Collection
object.
Fixed in 4.0.45
-> https://github.com/nystudio107/craft-seomatic/releases/tag/4.0.45
Just out of curiosity, is this also an issue in SEOmatic 3.x.x
, or just on 4.x.x
and 5.x.x
?
Just 4.x and 5.x, it had to do with collections
Got it, thanks!