Jet\Form_Definition_Interface

The interface that a class must implement if it is to be automatically mapped to forms.

Overview of methods

Method Meaning of
public getFormFieldsDefinition(
) : Form_Definition_Field[]
Returns the definitions of the form fields of the given class.
public createForm(
string $form_name,
array $only_fields=[],
array $exclude_fields=[]
) : Form
By definition, it creates a form.

Parameters:
  • $form_name
    Name of form.
  • $only_fields
    List of fields from the definition that the form should consist of. Other fields will be excluded. It is possible to use the wildcard character '*' - see below.
  • $exclude_fields
    List of fields from the definition that must not be in the form. It is possible to use the wildcard character '*' - see below.


Functioning of filters
Both the $only_fields and $exclude_fields filters have the option to use the * character. How it works: In the previous chapter, we showed an example with a hypothetical product in an e-commerce store. Now, let's say we only need a form to edit the product descriptions and nothing else. But to edit the descriptions in all locales. Let's do it like this: $edit_form $product->createForm
       
form_name'edit_form',  
       
only_fields: ['/localized/*/description']
);
Or let's say we need a form that has all the basic data and also all the localized data, but only for a specific locale. This can then be done as follows: $edit_form $product->createForm
       
form_name'edit_form',  
       
only_fields: [
               
'*',
               
'/localized/'.$some_locale.'/*'
       
]
);
And it is understandably not a problem to create a form with an exact list of fields. For example, if we need to edit only internal codes and EANs: $edit_form $product->createForm
       
form_name'edit_form',  
       
only_fields: [
               
'internal_code',
               
'EAN',
       ]
);
Previous chapter
Mapping classes to forms
Next chapter
Jet\Form_Definition_Trait