sulu / SuluHeadlessBundle

Bundle that provides controllers and services for using Sulu as headless content management system
MIT License
45 stars 25 forks source link

difference in preview vs Sulu data object (array vs object) - settings property #117

Open DanielRuf opened 2 years ago

DanielRuf commented 2 years ago

It looks like there is some difference in the settings property.

Is this already known, a bug, feature or something else due to typecasting?

preview:

image (4)

frontend:

image (2)

mage (3)

The logic seems to come from here:

https://github.com/sulu/SuluHeadlessBundle/blob/0.x/Content/ContentTypeResolver/BlockResolver.php#L73

$content[$i] = ['type' => $blockPropertyType->getName(), 'settings' => $blockPropertyType->getSettings()];

I guess in the preview it should also be an object? Not sure if it is because of the logic of getValue() for block properties combined with the normalization.

alexander-schranz commented 2 years ago

Thx for reporting. Interesting that it is even a object on the website would it expected that if empty array also there how the code is written. But good to know that it atleast is correctly normalized there. I think we need to have a deeper look at it.

If you want to have a look at it it would be interesting what dump($blockPropertyType->getSettings()); returns you in the preview and what it returns on the website?

DanielRuf commented 2 years ago

If you want to have a look at it it would be interesting what dump($blockPropertyType->getSettings()); returns you in the preview and what it returns on the website?

In which files and locations would that be for Sulu preview and Sulu headless output?

alexander-schranz commented 2 years ago

The line you mention here: https://github.com/sulu/SuluHeadlessBundle/blob/0.x/Content/ContentTypeResolver/BlockResolver.php#L73

You can also use xdebug with a breakpoint there to debug it.

DanielRuf commented 2 years ago

Hm, I'm a bit confused.

returns you in the preview and what it returns on the website

Is the same line called in both views?

alexander-schranz commented 2 years ago

Is the same line called in both views?

Yes once you need to debug it in the preview and once when rendered on the website.

DanielRuf commented 2 years ago

frontend:

image

preview:

image

Tested with var_dump since dump did not work for both, only for preview.

alexander-schranz commented 2 years ago

Okay that helps a little bit. Would be itneresting where the stdClass comes from as that should also be the case then in the preview. But I think maybe its already saved that way and as the preview is not saved it is outputted this way. A workaround would be empty($settings) ? new \stdClass() : $settings at that line.

DanielRuf commented 2 years ago

Would be itneresting where the stdClass comes from as that should also be the case then in the preview.

Definitely interesting, yes.

But I think maybe its already saved that way and as the preview is not saved it is outputted this way.

Same happens when the page is saved + published.

image

A workaround would be empty($settings) ? new \stdClass() : $settings at that line.

Sounds like a feasible solution.