[739 Aufrufe]

5.6 Hooks: comment

In diesem Abschnitt beschäftigen wir uns mit den Hooks für die Kommentare.

Hook: addComment

Der addComment Hook wird aufgerufen, wenn ein Kommentar erstellt wird.

Registrierung

# /src/Ctocb/Example/Resources/config/services.yml
services:

  # Hooks
  Ctocb\Example\Classes\Contao\Hooks\ExampleHook:
    public: true
    tags:
      - { name: contao.hook, hook: addComment, method: handleHook, priority: 1024 }

Klasse

<?php

namespace Ctocb\Example\Classes\Contao\Hooks;

use Contao\Comments;

class ExampleHook {

    public function handleHook(int $commentId, array $commentData, Comments $comments): void
    {
        // Do something ...
    }
}

Parameter:

Parameter Typ Beschreibung
$commentId int Id des neuen Kommentars
$commentData array Zeitstempel des neuen Kommentars
$comments \Contao\Comments Instanz von \Contao\Comments, dass den Hook aufgerufen hat

Rückgabewert:

keiner

Referenz im Contao Core: \Contao\Comments#L371-L379

Hook: isAllowedToEditComment

Der isAllowedToEditComment Hook wurde bereits unter "Hooks: backend" besprochen.

Hook: listComments

Der listComments Hook wurde bereits unter "Hooks: backend" besprochen.