terminal42 / contao-node

Manage content centrally as nodes and reuse them everywhere.
MIT License
29 stars 8 forks source link

Warning: Attempt to read property "nodes" on array #40

Closed ameotoko closed 2 years ago

ameotoko commented 2 years ago

In content element "Nodes", when I select nodes in the picker and click "Apply" – that AJAX request fails with server error (500) in dev environment with PHP 8.1. The reason is the PHP 8 Warning: Attempt to read property "nodes" on array:

ErrorException:
Warning: Attempt to read property "nodes" on array

  at vendor/terminal42/contao-node/src/EventListener/DataContainerListener.php:321
  at Terminal42\NodeBundle\EventListener\DataContainerListener->reloadNodePickerWidget(object(DC_Table))
     (vendor/terminal42/contao-node/src/EventListener/DataContainerListener.php:260)
  at Terminal42\NodeBundle\EventListener\DataContainerListener->onExecutePostActions('reloadNodePickerWidget', object(DC_Table))
     (vendor/contao/core-bundle/src/Resources/contao/classes/Ajax.php:527)
  at Contao\Ajax->executePostActionsHook(object(DC_Table))
     (vendor/contao/core-bundle/src/Resources/contao/classes/Ajax.php:509)
  at Contao\Ajax->executePostActions(object(DC_Table))
     (vendor/contao/core-bundle/src/Resources/contao/classes/Backend.php:429)
  at Contao\Backend->getBackendModule('article', null)
     (vendor/contao/core-bundle/src/Resources/contao/controllers/BackendMain.php:168)
  at Contao\BackendMain->run()
     (vendor/contao/core-bundle/src/Controller/BackendController.php:49)
  at Contao\CoreBundle\Controller\BackendController->mainAction()
     (vendor/symfony/http-kernel/HttpKernel.php:152)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:74)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:202)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (public/index.php:44)

When I fix src/EventListener/DataContainerListener.php:321 to use array notation instead, then the next code block fails with another warning:

ErrorException:
Warning: Undefined array key "load_callback"

  at vendor/terminal42/contao-node/src/EventListener/DataContainerListener.php:326
  at Terminal42\NodeBundle\EventListener\DataContainerListener->reloadNodePickerWidget(object(DC_Table))
     (vendor/terminal42/contao-node/src/EventListener/DataContainerListener.php:260)
  at Terminal42\NodeBundle\EventListener\DataContainerListener->onExecutePostActions('reloadNodePickerWidget', object(DC_Table))
     (vendor/contao/core-bundle/src/Resources/contao/classes/Ajax.php:527)
  at Contao\Ajax->executePostActionsHook(object(DC_Table))
     (vendor/contao/core-bundle/src/Resources/contao/classes/Ajax.php:509)
  at Contao\Ajax->executePostActions(object(DC_Table))
     (vendor/contao/core-bundle/src/Resources/contao/classes/Backend.php:429)
  at Contao\Backend->getBackendModule('article', null)
     (vendor/contao/core-bundle/src/Resources/contao/controllers/BackendMain.php:168)
  at Contao\BackendMain->run()
     (vendor/contao/core-bundle/src/Controller/BackendController.php:49)
  at Contao\CoreBundle\Controller\BackendController->mainAction()
     (vendor/symfony/http-kernel/HttpKernel.php:152)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:74)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:202)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (public/index.php:44)
aschempp commented 2 years ago

see https://github.com/terminal42/contao-node/pull/41