The compileFormFields
hook is triggered when the fields of a form are compiled.
It passes the form fields, the ID of the form and the form object as arguments
and expects the modified form fields as return value.
array $fields
An array of \Contao\FormFieldModel
instances.
string $formId
Alias of the current form. Used in the value
attribute of the hidden form
field FORM_SUBMIT
. Don’t confuse with $objForm->id
.
\Contao\Form $form
The form (an instance of \Contao\Form
).
An array
of of \Contao\FormFieldModel
instances.
// src/EventListener/CompileFormFieldsListener.php
namespace App\EventListener;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
use Contao\Form;
#[AsHook('compileFormFields')]
class CompileFormFieldsListener
{
public function __invoke(array $fields, string $formId, Form $form): array
{
// Modify $fields as needed
return $fields;
}
}