Forms

Generic Form

Mayd Core provides a default form template, that can be used for a generic backend form. It automatically renders abort links, uses the correct form theme and can handle the breadcrumb.

You can use this generic form in any backend controller:

class SomeBackendController extends AbstractController
{
    public function doSomething ()
    {
        return $this->render("@MaydCore/form/generic-form.html.twig", [
            "pageTitle" => "My Backend Form",
            "form" => $form->createView(),
        ]);
    }
}

You can pass the following parameters:

return $this->render("@MaydCore/form/generic_form.html.twig", [
    // pass these parameters here
]);
parameters
nametypedescription
formFormViewThe form to render the template for.
pageTitlestringWill be used as page title and meta title. Will be translated in the form domain.
abortUrlstringThe URL where the abort button will link to.
pageTitleParametersarrayThe parameters, that are needed to translate the pageTitle translation key. Will be passed to the trans() call as parameters. (optional)
proceedLabelstringThe translation key, that translates to the label of the "proceed" button. Will be translated in the form domain. (optional)
abortLabelstringThe translation key, that translates to the label of the "abort" button. Will be translated in the form domain. (optional)
breadcrumbarray<string, string|null>The entries of the breadcrumb, mapping of label -> url.

Manually Creating Forms

Backend forms work basically exactly like in a regular Symfony application. The only thing you need to adjust is to load the Mayd form themes, so that all custom form elements are working correctly.

All registered form themes (from the core and from extensions) are available via a twig function:

{%- form_theme form with mayd_form_themes() -%}

If you need to create a custom form theme for a specific field, you need to enlist your form theme file in the mayd.yaml.