The getForm
allows to manipulate the generation of the forms. It passes the
form object and the current form output buffer as arguments and expects a string
as return value.
\Contao\FormModel $formModel
Database result set from table tl_form
as a \Contao\FormModel
instance.
string $buffer
The generated form buffer.
\Contao\Form $form
The Form object.
Return $buffer
or your custom modification.
// src/EventListener/GetFormListener.php
namespace App\EventListener;
use Contao\CoreBundle\ServiceAnnotation\Hook;
use Contao\Form;
use Contao\FormModel;
/**
* @Hook("getForm")
*/
class GetFormListener
{
public function __invoke(FormModel $formModel, string $buffer, Form $form): string
{
if (2 === (int) $form->id) {
// Do something …
}
return $buffer;
}
}