craft-seomatic icon indicating copy to clipboard operation
craft-seomatic copied to clipboard

Aggregated data from matrix-field returns strange values

Open stefanfriedrich opened this issue 1 year ago • 2 comments

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

Bildschirmfoto 2024-02-13 um 18 01 37 Bildschirmfoto 2024-02-13 um 19 17 42 Bildschirmfoto 2024-02-13 um 19 11 51

Versions

  • Plugin version: 4.0.37
  • Craft version: 4.5.11.1

stefanfriedrich avatar Feb 13 '24 18:02 stefanfriedrich

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?

khalwat avatar Feb 13 '24 19:02 khalwat

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.

stefanfriedrich avatar Feb 14 '24 06:02 stefanfriedrich

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?

khalwat avatar Mar 07 '24 22:03 khalwat

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

khalwat avatar Mar 08 '24 18:03 khalwat

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.

khalwat avatar Mar 22 '24 02:03 khalwat

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.

khalwat avatar Mar 22 '24 20:03 khalwat

Fixed in 4.0.45 -> https://github.com/nystudio107/craft-seomatic/releases/tag/4.0.45

khalwat avatar Mar 22 '24 20:03 khalwat

Just out of curiosity, is this also an issue in SEOmatic 3.x.x, or just on 4.x.x and 5.x.x?

martinhellwagner avatar May 06 '24 12:05 martinhellwagner

Just 4.x and 5.x, it had to do with collections

khalwat avatar May 06 '24 16:05 khalwat

Got it, thanks!

martinhellwagner avatar May 06 '24 16:05 martinhellwagner