Open dennisbohn opened 8 months ago
@leofeyer @ausi any idea why this is happening?
I guess this is caused by $nodeId = $dc->id;
on line 63 as $dc->id
refers to the ID of the content element and not the node.
Yeah, this extension is not compatible with nested elements at the moment. Simple as that. I'll tag this as a feature because we'll have to introduce support for them, in whichever way we'll do that.
This fix worked for me.
https://github.com/terminal42/contao-node/compare/main...dennisbohn:contao-node:main
The ContentListener.php class contains an additional method to iterate through content elements.
private function findNodeIdByContentId($contentId): int
{
$pid = $contentId;
$ptable = 'tl_content';
// Recursive node id finder
while ($ptable === 'tl_content') {
list($pid, $ptable) = $this->db->fetchNumeric('SELECT pid, ptable FROM tl_content WHERE id=?', [$pid]);
}
return $pid;
}
The onLoadCallback method has been changed to the new method.
public function onLoadCallback(DataContainer $dc): void
{
switch (Input::get('act')) {
case 'edit':
case 'delete':
case 'show':
case 'copy':
case 'copyAll':
case 'cut':
case 'cutAll':
$nodeId = $this->findNodeIdByContentId($dc->id);
break;
case 'paste':
if ('create' === Input::get('mode')) {
$nodeId = $dc->id;
} else {
$nodeId = $this->findNodeIdByContentId($dc->id);
}
break;
case 'create':
// Nested element
if (Input::get('ptable') === 'tl_content') {
$nodeId = $this->findNodeIdByContentId(Input::get('pid'));
} else {
$nodeId = $dc->id;
}
break;
default:
// Ajax requests such as toggle
if (Input::get('field') && ($id = Input::get('cid') ?: Input::get('id'))) {
$nodeId = $this->findNodeIdByContentId($id);
// Nested element
} else if (Input::get('ptable') === 'tl_content') {
$nodeId = $this->findNodeIdByContentId($dc->id);
} else {
$nodeId = $dc->id;
}
break;
}
$type = $this->db->fetchOne('SELECT type FROM tl_node WHERE id=?', [$nodeId]);
// Throw an exception if the node is not present or is of a folder type
if (!$type || NodeModel::TYPE_FOLDER === $type) {
throw new AccessDeniedException('Node of folder type cannot have content elements');
}
$this->checkPermissions((int) $nodeId);
}
Create, copy, edit, delete, moving, info and toggle works fine inside and outside the element group. Nested element groups are also possible. But it feels that it needs some more testing. I'm not sure what all needs to be taken into account when it comes to ajax requests.
When an element group is included in a node and I want to edit the child elements, I currently get an error message.
If I comment out lines 71 - 73 in the "ContentListener.php", I can edit the entries.
https://github.com/terminal42/contao-node/blob/842fc326c1b5c97341645989dfef18eaa05cb00a/src/EventListener/ContentListener.php#L71-L73