The isAllowedToEditComment
hook is triggered to determine permission on a
comment from unknown source in the back end. It passes the comment parent ID and
source table and expects a boolean as return value.
int $parentId
The parent record ID.
string $parentTable
The parent table name.
If you return true
, access to the comment is granted. Return false
if access
is prohibited or your function is not responsible for this comment.
// src/EventListener/IsAllowedToEditCommentListener.php
namespace App\EventListener;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
#[AsHook('isAllowedToEditComment')]
class IsAllowedToEditCommentListener
{
public function __invoke(int $parentId, string $parentTable): bool
{
// Check the access to your custom module
if (\Contao\BackendUser::getInstance()->hasAccess('custom', 'modules')) {
return true;
}
return false;
}
}