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

genericImage on entity model is typecast as an array but returns a string

Open jamesmacwhite opened this issue 2 years ago • 1 comments

Describe the bug

The genericImage property on the entity model is declared to return an array but returns a string, dumping the contents of this command, returns a string for me.

Seomatic::$plugin->metaBundles->getGlobalMetaBundle(1)->metaSiteVars->identity->genericImage

This is for Craft CMS 3, although it is the same on Craft CMS 4.

To reproduce

Steps to reproduce the behaviour:

  1. Output the genericImage property from the meta site vars
  2. Observe the output is a string not an array as declared on the model

jamesmacwhite avatar Aug 09 '22 18:08 jamesmacwhite

I think it might be mis-typed, and should indeed be a string. Are you having an issue related to it?

khalwat avatar Aug 09 '22 23:08 khalwat

I'm having issues if I try and write my docblocks for example if I was to do:

private function _genericSeoImage(): string
{
    return Seomatic::$plugin->metaBundles->getGlobalMetaBundle(1)->metaSiteVars->identity->genericImage;
}

I can't declare return as string, because it would conflict and mismatch. Technically not an issue for Craft 3 as it's less strict and can avoid doing it entirely, it would be an issue with Craft CMS 4. Equally declaring as array, will then break other things as it will be a string not an array.

jamesmacwhite avatar Aug 10 '22 07:08 jamesmacwhite

Thanks, will have a look

khalwat avatar Aug 10 '22 14:08 khalwat

Yeah that's the resolved image, it should be a string. Addressed in: https://github.com/nystudio107/craft-seomatic/commit/c1fe6e55f75a57339d8eedaab2f83ea44ae6a63e & https://github.com/nystudio107/craft-seomatic/commit/566aa6709d889ba3ec6e97270dc4acd9cc03ef77

Craft CMS 3:

You can try it now by setting your semver in your composer.json to look like this:

    "nystudio107/craft-seomatic": "dev-develop as 3.4.38”,

Then do a composer clear-cache && composer update

Craft CMS 4:

…..

You can try it now by setting your semver in your composer.json to look like this:

    "nystudio107/craft-seomatic": "dev-develop-v4 as 4.0.8”,

Then do a composer clear-cache && composer update

khalwat avatar Aug 10 '22 15:08 khalwat

Thanks for updating the typecast in the plugin! This should fix the issue!

jamesmacwhite avatar Aug 10 '22 17:08 jamesmacwhite