listComments

Details

This page shows version 4.x. The current version can be found here.

The listComments hook is triggered when listing comment from unknown source in the back end. It passes the current record as argument and expects a string as return value.

Parameters

  1. array $comment

    The current comment record data.

Return Values

Return a string representing your comment, or an empty string if your method is not responsible for the source table.

Example

// src/EventListener/ListCommentsListener.php
namespace App\EventListener;

use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;

#[AsHook('listComments')]
class ListCommentsListener
{
    public function __invoke(array $comment): string
    {
        if ('tl_mytable' === $comment['source']) {
            return '<a href="contao/main.php?do=…">' . $comment['title'] . '</a>';
        }

        return '';
    }
}

References