Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check why setPosition is set as null #1496

Closed
Tracked by #1495
eerison opened this issue Jul 26, 2022 · 16 comments
Closed
Tracked by #1495

Check why setPosition is set as null #1496

eerison opened this issue Jul 26, 2022 · 16 comments

Comments

@eerison
Copy link
Contributor

eerison commented Jul 26, 2022

I got this on branch 4.x

Sonata\BlockBundle\Model\BaseBlock::setPosition(): Argument #1 ($position) must be of type int, null given, called in /app/vendor/sonata-project/page-bundle/src/Entity/Transformer.php on line 157

Stack trace

TypeError:
Sonata\BlockBundle\Model\BaseBlock::setPosition(): Argument #1 ($position) must be of type int, null given, called in /app/vendor/sonata-project/page-bundle/src/Entity/Transformer.php on line 157

  at vendor/sonata-project/block-bundle/src/Model/BaseBlock.php:147
  at Sonata\BlockBundle\Model\BaseBlock->setPosition(null)
     (vendor/sonata-project/page-bundle/src/Entity/Transformer.php:157)
  at Sonata\PageBundle\Entity\Transformer->loadBlock(array('id' => 11, 'name' => 'container 1', 'enabled' => true, 'position' => null, 'settings' => array('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' => array(array('id' => 9, 'name' => 'Test A', 'enabled' => true, 'position' => 1, 'settings' => array('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' => array()), array('id' => 10, 'name' => 'test s', 'enabled' => true, 'position' => 2, 'settings' => array('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' => array()))), object(SnapshotPageProxy))
     (vendor/sonata-project/page-bundle/src/Model/SnapshotPageProxy.php:129)
  at Sonata\PageBundle\Model\SnapshotPageProxy->getBlocks()
     (vendor/sonata-project/page-bundle/src/CmsManager/CmsSnapshotManager.php:152)
  at Sonata\PageBundle\CmsManager\CmsSnapshotManager->loadBlocks(object(SnapshotPageProxy))
     (vendor/sonata-project/page-bundle/src/CmsManager/CmsSnapshotManager.php:133)
  at Sonata\PageBundle\CmsManager\CmsSnapshotManager->getPageBy(object(SonataPageSite), 'url', '/')
     (vendor/sonata-project/page-bundle/src/CmsManager/BaseCmsPageManager.php:54)
  at Sonata\PageBundle\CmsManager\BaseCmsPageManager->getPageByUrl(object(SonataPageSite), '/')
     (vendor/sonata-project/page-bundle/src/Route/CmsPageRouter.php:132)
  at Sonata\PageBundle\Route\CmsPageRouter->match('/')
     (vendor/symfony-cmf/routing/src/ChainRouter.php:192)
  at Symfony\Cmf\Component\Routing\ChainRouter->doMatch('/', object(Request))
     (vendor/symfony-cmf/routing/src/ChainRouter.php:158)
  at Symfony\Cmf\Component\Routing\ChainRouter->matchRequest(object(Request))
     (vendor/symfony/http-kernel/EventListener/RouterListener.php:112)
  at Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest(object(RequestEvent), 'kernel.request', object(TraceableEventDispatcher))
     (vendor/symfony/event-dispatcher/Debug/WrappedListener.php:126)
  at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(object(RequestEvent), 'kernel.request', object(TraceableEventDispatcher))
     (vendor/symfony/event-dispatcher/EventDispatcher.php:264)
  at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.request', object(RequestEvent))
     (vendor/symfony/event-dispatcher/EventDispatcher.php:239)
  at Symfony\Component\EventDispatcher\EventDispatcher->callListeners(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.request', object(RequestEvent))
     (vendor/symfony/event-dispatcher/EventDispatcher.php:73)
  at Symfony\Component\EventDispatcher\EventDispatcher->dispatch(object(RequestEvent), 'kernel.request')
     (vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:168)
  at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch(object(RequestEvent), 'kernel.request')
     (vendor/symfony/http-kernel/HttpKernel.php:134)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:80)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:201)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (public/index.php:29)   

But all my pages there are position value

Screenshot 2022-07-26 at 13 10 09

@Hanmac
Copy link
Contributor

Hanmac commented Jul 26, 2022

@eerison i might look into it, do you have a testcase for this to repoduce?

@eerison
Copy link
Contributor Author

eerison commented Jul 26, 2022

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!

@Hanmac
Copy link
Contributor

Hanmac commented Jul 26, 2022

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

@eerison
Copy link
Contributor Author

eerison commented Jul 26, 2022

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 ?

@Hanmac
Copy link
Contributor

Hanmac commented Jul 26, 2022

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

@eerison
Copy link
Contributor Author

eerison commented Jul 26, 2022

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.

@eerison
Copy link
Contributor Author

eerison commented Jul 26, 2022

@jordisala1991 BlockBundle requires position as integer

But how do you handle this for container block?

@eerison
Copy link
Contributor Author

eerison commented Jul 26, 2022

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

@jordisala1991
Copy link
Member

Looks like the Transformer.php could be changed to not assign null properties?

@Hanmac
Copy link
Contributor

Hanmac commented Jul 26, 2022

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?

@eerison
Copy link
Contributor Author

eerison commented Jul 26, 2022

the container block is used in sonata page only?

@VincentLanglet
Copy link
Member

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...

@eerison
Copy link
Contributor Author

eerison commented Jul 26, 2022

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

Screenshot 2022-07-26 at 16 34 28

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.

@eerison
Copy link
Contributor Author

eerison commented Jul 26, 2022

those blocks are added here

Screenshot 2022-07-26 at 16 47 08

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.

Screenshot 2022-07-26 at 16 50 15

But In 4.x branch someone started to remove some blocks 😃
Screenshot 2022-07-26 at 17 00 57

@VincentLanglet VincentLanglet added this to the 4.0 milestone Jul 26, 2022
@jordisala1991
Copy link
Member

Can you check with #1501 @eerison ?

@jordisala1991
Copy link
Member

This one should fix this problem: #1532

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants