Closed eerison closed 2 years ago
@eerison i might look into it, do you have a testcase for this to repoduce?
Hey @Hanmac I just updated from 3.x to 4.x using sonata 4, and it crash my page, if you test it in some project you can see this issue!
hm curious, you should probably check the content json data from your snapshots there is where the null is coming from but i don't know how it got there
Hey @Hanmac I guess you are right, it's related with snapshot content, the position of container is null
{
"id":642,
"name":"Homepage",
"javascript":null,
"stylesheet":null,
"raw_headers":null,
"title":null,
"meta_description":null,
"meta_keyword":null,
"template_code":"default",
"request_method":"GET|POST|HEAD|DELETE|PUT",
"created_at":"1656521887",
"updated_at":"1656522565",
"slug":"",
"parent_id":null,
"target_id":null,
"blocks":[
{
"id":11,
"name":"container 1",
"enabled":true,
"position":null,
"settings":{
"code":null,
"layout":"{{ CONTENT }}",
"class":null,
"template":"@SonataPage\/Block\/block_container.html.twig"
},
"type":"sonata.block.service.container",
"created_at":"1656522317",
"updated_at":"1656522349",
"blocks":[
{
"id":9,
"name":"Test A",
"enabled":true,
"position":1,
"settings":{
"mode":"form.choice_public",
"title":"Title B",
"translation_domain":null,
"icon":"fa fa-globe",
"class":null,
"template":"@SonataPage\/Block\/block_pagelist.html.twig"
},
"type":"sonata.page.block.pagelist",
"created_at":"1656521962",
"updated_at":"1656522564",
"blocks":[
]
},
{
"id":10,
"name":"test s",
"enabled":true,
"position":2,
"settings":{
"content":"Insert your custom content here",
"template":"@SonataBlock\/Block\/block_core_text.html.twig"
},
"type":"sonata.block.service.text",
"created_at":"1656522079",
"updated_at":"1656522388",
"blocks":[
]
}
]
}
]
}
in this case position id should be ?int
?
i don't know about BlockBundle to understand what the container is doing there and if the null position is valid there
if it does, then it needs to be fixed in BlockBundle
the container block is like the main container
for example:
header container block
- menu block
- ads block
content container block
- block 1 (assets list)
- block 2 (assets 2 list)
footer container block
- menu block
- sponsors block
I don't know if it was clear, but it's more or less the block
to keep others blocks
into like sections.
@jordisala1991 BlockBundle requires position as integer
But how do you handle this for container block
?
I guess the problem not related with position only!
I have others blocks that there isn't name
{
"id":652,
"name":"contact",
"javascript":null,
"stylesheet":null,
"raw_headers":null,
"title":null,
"meta_description":null,
"meta_keyword":null,
"template_code":"default",
"request_method":"GET|POST|HEAD|DELETE|PUT",
"created_at":"1656522709",
"updated_at":"1657119067",
"slug":"contact",
"parent_id":642,
"target_id":null,
"blocks":[
{
"id":15,
"name":"Top content",
"enabled":true,
"position":1,
"settings":{
"code":"content_top"
},
"type":"sonata.page.block.container",
"created_at":"1656571318",
"updated_at":"1656571318",
"blocks":[
{
"id":21,
"name":null,
"enabled":true,
"position":1,
"settings":{
"template":"@SonataSeo\/Block\/block_email_share_button.html.twig",
"subject":"subject test",
"body":"body test"
},
"type":"sonata.seo.block.email.share_button",
"created_at":"1656571654",
"updated_at":"1656571654",
"blocks":[
]
},
{
"id":22,
"name":null,
"enabled":true,
"position":2,
"settings":{
"mode":"form.choice_public",
"title":"ABBB",
"translation_domain":null,
"icon":"fa fa-globe",
"class":null,
"template":"@SonataPage\/Block\/block_pagelist.html.twig"
},
"type":"sonata.page.block.pagelist",
"created_at":"1656571709",
"updated_at":"1656571709",
"blocks":[
]
}
]
},
{
"id":16,
"name":"Main content",
"enabled":true,
"position":1,
"settings":{
"code":"content"
},
"type":"sonata.page.block.container",
"created_at":"1656571318",
"updated_at":"1656571318",
"blocks":[
{
"id":25,
"name":null,
"enabled":true,
"position":0,
"settings":{
"url":"https:\/\/facebook.com",
"title":"RSS feed",
"translation_domain":null,
"icon":"fa fa-rss-square",
"class":null,
"template":"@SonataBlock\/Block\/block_core_rss.html.twig"
},
"type":"sonata.block.service.rss",
"created_at":"1656574713",
"updated_at":"1657119037",
"blocks":[
]
},
{
"id":27,
"name":null,
"enabled":true,
"position":1,
"settings":{
"template":"@SonataSeo\/Block\/block_email_share_button.html.twig",
"subject":"test 12455",
"body":"test 4333"
},
"type":"sonata.seo.block.email.share_button",
"created_at":"1657118800",
"updated_at":"1657119037",
"blocks":[
]
},
{
"id":19,
"name":null,
"enabled":true,
"position":2,
"settings":{
"content":"SIMPLE TEXT :D",
"template":"@SonataBlock\/Block\/block_core_text.html.twig"
},
"type":"sonata.block.service.text",
"created_at":"1656571374",
"updated_at":"1657119037",
"blocks":[
]
},
{
"id":23,
"name":"aaa",
"enabled":true,
"position":3,
"settings":{
"title":"Breadcrumb (Homepage)",
"cache_policy":"public",
"template":"@SonataBlock\/Block\/block_core_menu.html.twig",
"menu_name":null,
"safe_labels":false,
"current_class":"active",
"first_class":null,
"last_class":null,
"current_uri":null,
"menu_class":"list-group",
"children_class":"list-group-item",
"menu_template":"@SonataSeo\/Block\/breadcrumb.html.twig",
"include_homepage_link":true,
"context":false
},
"type":"sonata.seo.block.breadcrumb.homepage",
"created_at":"1656571781",
"updated_at":"1657119037",
"blocks":[
]
},
{
"id":24,
"name":null,
"enabled":true,
"position":4,
"settings":{
"url":"https:\/\/google.com",
"title":"google link",
"translation_domain":null,
"icon":"fa fa-rss-square",
"class":null,
"template":"@SonataBlock\/Block\/block_core_rss.html.twig"
},
"type":"sonata.block.service.rss",
"created_at":"1656574614",
"updated_at":"1657119037",
"blocks":[
]
},
{
"id":26,
"name":"Instagram",
"enabled":true,
"position":5,
"settings":{
"url":"https:\/\/instagram.com",
"title":"INSTA PROD 45678",
"translation_domain":null,
"icon":"fa fa-rss-square",
"class":null,
"template":"@SonataBlock\/Block\/block_core_rss.html.twig"
},
"type":"sonata.block.service.rss",
"created_at":"1656574756",
"updated_at":"1657119037",
"blocks":[
]
}
]
},
{
"id":17,
"name":"Bottom content",
"enabled":true,
"position":1,
"settings":{
"code":"content_bottom"
},
"type":"sonata.page.block.container",
"created_at":"1656571318",
"updated_at":"1656571318",
"blocks":[
]
},
{
"id":18,
"name":"Footer",
"enabled":true,
"position":1,
"settings":{
"code":"footer"
},
"type":"sonata.page.block.container",
"created_at":"1656571318",
"updated_at":"1656571318",
"blocks":[
]
},
{
"id":14,
"name":"Header",
"enabled":true,
"position":1,
"settings":{
"code":"header"
},
"type":"sonata.page.block.container",
"created_at":"1656571318",
"updated_at":"1656571318",
"blocks":[
{
"id":20,
"name":"Menu 1",
"enabled":true,
"position":1,
"settings":{
"title":"sonata.block.menu",
"cache_policy":"public",
"template":"@SonataBlock\/Block\/block_core_menu.html.twig",
"menu_name":"sonata_admin_sidebar",
"safe_labels":false,
"current_class":"active",
"first_class":null,
"last_class":null,
"current_uri":null,
"menu_class":"list-group",
"children_class":"list-group-item",
"menu_template":null
},
"type":"sonata.block.service.menu",
"created_at":"1656571563",
"updated_at":"1656571563",
"blocks":[
]
}
]
}
]
}
and I got the same issue
Sonata\BlockBundle\Model\BaseBlock::setName(): Argument #1 ($name) must be of type string, null given, called in /app/vendor/sonata-project/page-bundle/src/Entity/Transformer.php on line 155
Looks like the Transformer.php could be changed to not assign null properties?
Looks like the Transformer.php could be changed to not assign null properties?
i think thats an hotfix for now
i checked BlockBundle code, the property says it can be null, the getter can return null values, but the setter can't set null values for some reason?
should that be fixed in BlockBundle too?
the container block is used in sonata page only?
i checked BlockBundle code, the property says it can be null, the getter can return null values, but the setter can't set null values for some reason?
should that be fixed in BlockBundle too?
The getter can return null
if no value was set.
For instance if you call (new Block())->getName()
.
But I assume the setter are not nullable, because this field were maybe supposed to be non-nullable in database.
I don't know if it makes sens to have a block without a name, a type or a position...
Where come from your data @eerison ?
should that be fixed in BlockBundle too?
The issue is that changing the param typehint will be a BC break...
I don't know if it makes sens to have a block without a name, a type or a position...
- IMO all blocks should have name too
- position, I'm not sure because it's container block is no a block that can be updated in the admin, it's more or less a fake block, it's just to group others blocks.
Where come from your data @eerison ?
when we create snapshot, it generates this content with the json
The issue is that changing the param typehint will be a BC break...
what we can do is
container position put value 0
and name = '', and we need to fix those blocks.
those blocks are added here
and it's the default blocks into the sonata page, probably we need to fix them to require name
, But some of them I would say that could be removed maybe.
But In 4.x branch someone started to remove some blocks 😃
Can you check with https://github.com/sonata-project/SonataPageBundle/pull/1501 @eerison ?
This one should fix this problem: https://github.com/sonata-project/SonataPageBundle/pull/1532
I got this on branch
4.x
Stack trace
But all my pages there are position value