[1358 Aufrufe]

5.10 Hooks: dca

In diesem Abschnitt beschäftigen wir uns mit den Hooks für das DCA.

Hook: executePostActions

Der executePostActions Hook wird aufgerufen, wenn eine Ajax-Anfrage eingeht, die ein DCA-Objekt benötigt.

Registrierung

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

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

Klasse

<?php

namespace Ctocb\Example\Classes\Contao\Hooks;

use Contao\DataContainer;

class ExampleHook {

    public function handleHook(string $action, DataContainer $dc): void
    {
        if ('update' === $action) {
            // Do something ...
        }
    }
}

Parameter:

Parameter Typ Beschreibung
$action string String mit dem Namen der Aktion
$dc \Contao\DataContainer DataContainer-Objekt

Rückgabewert:

keiner

Referenz im Contao Core: \Contao\Ajax.php#L183, \Contao\Ajax.php#L437-L439 und \Contao\Ajax.php#L444-L459

Hook: executePreActions

Der executePreActions Hook wird aufgerufen, wenn eine Ajax-Anfrage eingeht, die kein DCA-Objekt benötigt.

Registrierung

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

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

Klasse

<?php

namespace Ctocb\Example\Classes\Contao\Hooks;

class ExampleHook {

    public function handleHook(string $action): void
    {
        if ('update' === $action) {
            // Do something ...
        }
    }
}

Parameter:

Parameter Typ Beschreibung
$action string String mit dem Namen der Aktion

Rückgabewert:

keiner

Referenz im Contao Core: \Contao\Ajax.php#L153-L163

Hook: getAttributesFromDca

Der getAttributesFromDca Hook wurde bereits unter "Hooks: config" besprochen.

Hook: isAllowedToEditComment

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

Hook: isAllowedToEditComment

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

Hook: loadDataContainer

Der loadDataContainer Hook wird aufgerufen, wenn eine DCA-Datei geladen wird.

Registrierung

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

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

Klasse

<?php

namespace Ctocb\Example\Classes\Contao\Hooks;

class ExampleHook {

    public function handleHook(string $table): void
    {
        // Do something ...
    }
}

Parameter:

Parameter Typ Beschreibung
$table string String mit dem Namen der Tabelle

Rückgabewert:

keiner

Referenz im Contao Core: \Contao\DcaLoader#L98-L106

Hook: reviseTable

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