ns.forms
This filter is used to register or edit existing forms. On NexoPOS, forms are defined on the directory app/Forms and registered on the service provider app/Providers/FormsProvider.php. The filter ns.forms supports two parameters: the class that needs to be returned and the identifier that needs to be matched.
If NexoPOS tries to load a custom form with the identifier "your-custom-id", it will provide that value as an identifier, and while registering your class, you need to check if there is a match. Here is an example.
<?php
namespace Modules\YourModule\Providers;
use Illuminate\Support\ServiceProvider;
use Modules\YourModule\Forms\YourCustomForm;
class YourServiceProvier extends ServiceProvider
{
public function boot()
{
Hook::addFilter( 'ns.forms', function( $class, $identifier ) {
switch ( $identifier ) {
case 'your-custom-id':
return new YourCustomForm;
}
return $class;
}, 10, 2 );
}
}
We're here to define a custom form on our module that has the identifier "YourModule". Every time NexoPOS needs a form with the identifier "your-custom-id", it will have the class "YourCustomForm". If the $identifier doesn't match our identifier, we must return the $class value. This is necessary as the form might be defined and handled by either the core or another module.