Forms can be extended using a pipeline from your modules service providers setup method or your projects app service providers boot method. You can read more about pipelines in the article "Introduction to pipelines".
Adding a Field
To add fields to a form you can use the addSection, addSectionBefore, or addSectionAfter methods from within the pipeline.
addSection Method
This method accepts a key and a view to be injected. A field added with this method will be added as the first field.
addSectionBefore Method
This method accepts the same parameters as the addSection method but additionally accepts a third parameter, the key of the field this new field should be added before.
addSectionAfter Method
This method accepts the same parameters as the addSection method but additionally accepts a third parameter, the key of the field this new field should be added after.
Finding the Current Field Keys
If you do not know the keys of the current fields you can use this code snippet to dump the current keys when visiting the page with the form.
<?php
namespace Acme\MyModule;
use Aero\AccountArea\Http\Forms\AccountAddressForm;
use Aero\Common\Providers\ModuleServiceProvider;
class ServiceProvider extends ModuleServiceProvider
{
public function setup()
{
AccountAddressForm::extend(function ($form) {
dd($form->getSections()->keys()->toArray());
});
}
}
<?php
namespace Acme\MyModule;
use Aero\AccountArea\Http\Forms\AccountAddressForm;
use Aero\Common\Providers\ModuleServiceProvider;
class ServiceProvider extends ModuleServiceProvider
{
public function setup()
{
AccountAddressForm::extend(function ($form) {
$form->addSection('my-section', 'my-view');
});
}
}
Removing a Field
You can use the removeSection method within the pipeline to remove a field from a form. The methods expect one parameter, the key of the field that you would like to remove.
<?php
namespace Acme\MyModule;
use Aero\AccountArea\Http\Forms\AccountAddressForm;
use Aero\Common\Providers\ModuleServiceProvider;
class ServiceProvider extends ModuleServiceProvider
{
public function setup()
{
AccountAddressForm::extend(function ($form) {
$form->removeSection('line2');
});
}
}