wintercms / wn-blocks-plugin

Block based content management plugin for Winter CMS.
MIT License
20 stars 5 forks source link

Block config not always of the same type in block PHP section #23

Open damsfx opened 10 months ago

damsfx commented 10 months ago

Context :

a block that define a config according to the documentation.

Case 1 :
Block added to the page, nothing changed in content, open/close the config inspector, page saved.
The config is available in the PHP section of the block as a sdtClass.

{
  +"size": ""
  +"bg_color": ""
}

Case 2 :
Block added to the page, nothing changed in content, page saved.
The config is available in the PHP section of the block as an array.

array:2 [
  "size" => null
  "bg_color" => null
]

Workaround :

Strictly typing the configuration,
As an array :

$config = json_decode(json_encode($this->config), true);

As an stdClass :

$config = json_decode(json_encode($this->config));
LukeTowers commented 10 months ago

Can we have a PR that just always converts it to either a stdClass or an array?

damsfx commented 10 months ago

Can we have a PR that just always converts it to either a stdClass or an array?

It's on my to-do list ... but I'm running out of time.
A PR draft to add sorting on relationships has already taken up a lot of my time, but I'm getting there I think.

Which type do you think is best? @bennothommo, perhaps you have an opinion on the subject?

bennothommo commented 10 months ago

Since configs are ultimately stored through Halcyon (ie. the static content files in the theme), I think it should be an array for the best compatibility with that.

LukeTowers commented 10 months ago

Block configs do not have to be used only with static pages, so I wouldn't necessarily use that as the deciding factor @bennothommo unless it actively causes issues to be in an stdClass form.

But yes, for simplicities sake I would prefer they were stored as arrays.