Skip to content

Configuration overview

Alexey Dobrovolsky edited this page Sep 13, 2020 · 4 revisions

Configuration files

After publishing package files you can find configuration files in your config\easy_form directory. You can find the following files there:

aliases.php
config.php
defaults.php
config.php
forms.php
handlers.php
templates.php

aliases.php

File contains list of aliases for each html object, it need to create html element in form configuration or add plugin to. When creating custom forms or plugins, you will need to add your created class here.

config.php

This file contains common package configuration. By default it contains only forms key, which contains array of dot notated keys to yours forms definitions, when the builder is initialized, the config data will be merged.

defaults.php

This file contains default configuration for form elements. You can apply any defaults for each form element adding some form configuration to common key of array or apply to specific html object using types key. As example, for adding to inputs bootstrap class yours configuration may looks like:

<?php
return [
    'common' => [],
    'types' => [
        Dobrik\LaravelEasyForm\Forms\Html\Select::class => [
            'class' => 'form-control'
        ],
        Dobrik\LaravelEasyForm\Forms\Html\Input::class => [
            'class' => 'form-control'
        ],
        Dobrik\LaravelEasyForm\Forms\Html\Textarea::class => [
            'class' => 'form-control'
        ],
    ]
];

Also you can use interfaces:

Dobrik\LaravelEasyForm\Forms\Interfaces\HasContentInterface
Dobrik\LaravelEasyForm\Forms\Interfaces\HasValueInterface

forms.php

This file by default contains configuration forms definition, their structure and fields. Each file key is form configuration and have to be an array.

handlers.php

This file contains array divided like defaults.php to common and types keys. Each handler implements Dobrik\LaravelEasyForm\Handlers\HandlerInterface. The list of handlers is determined when building each element. Handlers from the 'common' key are merged with the 'types' key, with checking the instance of the html object and unified. Further handling proceed using the Laravel pipeline. Each handler has access to Dobrik\LaravelEasyForm\Handlers\Payload\Payload object, which contains Container, Builder, Factory, element configuration, array of form data and HtmlAbstract - handled object.

templates.php

Sometimes you need to use the same input, buttons or blocks in same structure. You can define one time your template configuration and reuse them in your form configuration using template form element type. As example, form save button in div element:

<?php
return [
    'save_buttons' => [
        'type' => 'Div',
        'class' => 'container',
        'child' => [
            [
                'title' => 'Save',
                'type' => 'Button',
                'class' => 'btn btn-success'
            ]
        ]
    ]
];

Using in form:

[
    'type' => 'template',
    'name' => 'save_buttons'
]

Each configuration will be discussed further in other sections of the documentation.

Clone this wiki locally