terminal42 / contao-node

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

Error: Node of folder type cannot have content elements #16

Closed saress closed 4 years ago

saress commented 5 years ago

I have a content node and inside there is a single text element with some content in it.

If I add a link to the text, everything works fine if I choose a "page" or a "file" with the picker. If I add a "news" element or an "event" element and save the content element, it will result to the error shown above. I guess it would be the same with a "faq" element.

The node it self is inside a node-folder, but it makes no difference if I move it outside a node folder. I have the latest contao-node version installed on a Contao 4.4.42 LTS.

Kind regards, Sares

fritzmg commented 4 years ago

I can confirm the problem. The problematic code is this:

https://github.com/terminal42/contao-node/blob/b7e8a629a0f4ba02226d77aa2454ca021ddf4f71/src/EventListener/ContentListener.php#L49-L54

Under certain circumstances, CURRENT_ID will be the ID of a tl_content entry, and not a tl_node entry and thus !$node || NodeModel::TYPE_FOLDER === $node will likely be true.

Not sure how to fix this though. May be check for null === Input::get('act') or something?

qzminski commented 4 years ago

Should be fixed in 1a3374a. It should make its way to the next minor version which should be released this week.

qzminski commented 4 years ago

The problem should be fixed already in 1.1.1 πŸ‘πŸ»

coffeincode commented 4 years ago

Nope, I'm sorry. I have 1.1.1 and I'm running into this problem :(

qzminski commented 4 years ago

Can you tell me exactly how to reproduce it? These are my steps:

  1. Go to node content elements list view.
  2. Create a new content element of "Text" type.
  3. Insert some news link inside the "Text" field.
  4. Save the content element.
fritzmg commented 4 years ago

Hm, I can also reproduce the problem in 1.1.1, though I my case I don't even have to open a link picker or anything. The error occurs when I go into an existing node and click on New element.

Contao\CoreBundle\Exception\AccessDeniedException:
Node of folder type cannot have content elements

  at vendor\terminal42\contao-node\src\EventListener\ContentListener.php:59
  at Terminal42\NodeBundle\EventListener\ContentListener->onLoadCallback(object(DC_Table))
     (vendor\contao\core-bundle\src\Resources\contao\drivers\DC_Table.php:202)
  at Contao\DC_Table->__construct('tl_content', array('tables' => array('tl_node', 'tl_content')))
     (vendor\contao\core-bundle\src\Resources\contao\classes\Backend.php:401)
  at Contao\Backend->getBackendModule('nodes', null)
     (vendor\contao\core-bundle\src\Resources\contao\controllers\BackendMain.php:131)
  at Contao\BackendMain->run()
     (vendor\contao\core-bundle\src\Controller\BackendController.php:55)
  at Contao\CoreBundle\Controller\BackendController->mainAction()
     (vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php:151)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php:68)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php:200)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (web\app_dev.php:68)

$type is false in this case. And $dc->id is the ID of the node.

Everything works fine if I change it to this:

-if ($dc->table === 'tl_content' && Input::get('act')) {
+if ($dc->table === 'tl_content' && 'edit' === Input::get('act')) {
qzminski commented 4 years ago

You're right @fritzmg, thanks for the input. I have just released 1.1.2 which should definitely close the case.

fritzmg commented 4 years ago

Unfortunately the same error still occurs with act=paste&mode=cut (click on the icon to move a content element).

qzminski commented 4 years ago

@fritzmg can you test 8d252f8 please?

fritzmg commented 4 years ago

@fritzmg can you test 8d252f8 please?

Unfortunately that will again produce the error, when you simply want to create an element 😬. It's frustrating working around these DCA/Contao back end convolutions, I know 😁

qzminski commented 4 years ago

Hmm under what circumstances would it? I just tried to create a content element and it worked fine.

fritzmg commented 4 years ago

Hm, no special circumstances as far as I can tell. I have an existing node (which is a sub node of a parent folder node) with existing content elements. If I click on New element, the error occurs.

Contao\CoreBundle\Exception\AccessDeniedException:
Node of folder type cannot have content elements

  at vendor\terminal42\contao-node\src\EventListener\ContentListener.php:59
  at Terminal42\NodeBundle\EventListener\ContentListener->onLoadCallback(object(DC_Table))
     (vendor\contao\core-bundle\src\Resources\contao\drivers\DC_Table.php:202)
  at Contao\DC_Table->__construct('tl_content', array('tables' => array('tl_node', 'tl_content')))
     (vendor\contao\core-bundle\src\Resources\contao\classes\Backend.php:401)
  at Contao\Backend->getBackendModule('nodes', null)
     (vendor\contao\core-bundle\src\Resources\contao\controllers\BackendMain.php:131)
  at Contao\BackendMain->run()
     (vendor\contao\core-bundle\src\Controller\BackendController.php:55)
  at Contao\CoreBundle\Controller\BackendController->mainAction()
     (vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php:151)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php:68)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php:200)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (web\app_dev.php:68)
Variable/Expression Content Comment
$dc->table "tl_content"
$dc->id "2" 2 is the ID of the node
Input::get('act') "paste"

Link for New element:

…/contao?do=nodes&table=tl_content&id=2&act=paste&mode=create&rt=…&ref=…
fritzmg commented 4 years ago

Note: creating a new element with the (βž•) link works fine. Did you try with New element (Contao 4.4) / New (Contao 4.9)?

qzminski commented 4 years ago

This is pure madness… I tested 2fd899d and it seems to work, mind checking as well, please? πŸ˜‡

fritzmg commented 4 years ago

This works - however, unfortunately I was able to move a content element into a node of type folder by manipulating the paste URL 😬

…/contao?do=nodes&table=tl_content&id=27990&act=cut&mode=2&pid=2&rt=…&ref=…

If you change the pid of that URL to an ID of a folder node, then the AccessDeniedException is not thrown.

qzminski commented 4 years ago

@fritzmg break this one 6e52151 πŸ˜‰

fritzmg commented 4 years ago

omg 😁 too bad there is no easier way to do this..?

I'll test some time today.

fritzmg commented 4 years ago

Looks fine as far as I have tested πŸ‘

qzminski commented 4 years ago

1.1.3 has been released. @saress @coffeincode please update your systems.