Code example
Example of how to create a simple subclass of \FluidTYPO3\Flux\Form and utilise the initializeObject method to create new fields upon Form instance creation. Also includes an example on how to use a Provider to return different Form instances based on arbitrary values.
- Description
- No description entered in Gist data (only local summary will be displayed)
- Author
- NamelessCoder
- Creation date
- Extensions
- FluidTYPO3.Flux
- Tags
- Forms Provider
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace MyVendor\MyExt\Form; | |
| class CustomForm extends \FluidTYPO3\Flux\Form { | |
| /** | |
| * Creates objects inserted into this Form, resulting in | |
| * a nested set of PHP objects that correspond exactly | |
| * to what would come out of parsing a Flux template | |
| */ | |
| public function initializeObject() { | |
| $this->createField('Input', 'test')->setDefault('default value')->setRequired(TRUE); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace MyVendor\MyExt\Provider; | |
| class CustomProvider extends \FluidTYPO3\Flux\Provider\ContentProvider implements \FluidTYPO3\Flux\Provider\ProviderInterface { | |
| /** | |
| * Gets a special Form instance, if one applies, to be returned | |
| * instead of the basic Flux Form instance | |
| */ | |
| public function getForm(array $row) { | |
| $templateFile = $this->getTemplatePathAndFilename($row); | |
| switch (basename($templateFile)) { | |
| ... | |
| case 'whatever.html': | |
| $form = $this->objectManager->get('MyVendor\MyExt\Form\CustomForm'); | |
| break; | |
| } | |
| return $form; | |
| } | |
| } |