portrino/px_validation

Extbase validation via TypoScript

Installs: 412

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 6

Forks: 1

Open Issues: 0

Type:typo3-cms-extension

1.2.1 2019-10-25 09:30 UTC

This package is auto-updated.

Last update: 2021-06-10 13:28:34 UTC


README

Extbase Validation via Typoscript

The PxValidation extension enables the possibility to define different validation configuration in your TypoScript for each Extbase-Controller-Action without touching the affected extension itself. This makes it easy to change the default validation behaviour of vendor extensions without changing their code. But the greatest benefit is that it opens the option to declare multiple variants of validation rules within one page tree. It is even possible to nest validation rules, so you can validate child objects.

Before you start: Include Static Template Files!

Example:

PHP:

namespace VendorName\ExtensionName\Controller;

class FooController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
    
    /**
     * action create
     *
     *
     * @param \VendorName\ExtensionName\Domain\Model\FooBar $fooBar
     * @return void
     */
    public function createAction(\VendorName\ExtensionName\Domain\Model\FooBar $fooBar) {
        ...       
    }
}

TypoScript:

plugin.tx_pxvalidation.settings {
    VendorName\ExtensionName\Controller\FooController {
        createAction {
            fooBar {
                overwriteDefaultValidation = 1 # validation rules defined in the property, model or controller are NOT executed
                objectValidators {
                    0 = VendorName\ExtensionName\Domain\Validator\FooValidator(firstOption=value1, secondOption=123456)
                    1 = VendorName\ExtensionName\Domain\Validator\BarValidator(firstOption=value1)
                }
                propertyValidators {
                    foo {
                        0 = NotEmpty
                    }
                    bar {
                        0 = NotEmpty
                        1 = StringLength(minimum=3)
                        2 = VendorName\ExtensionName\Domain\Validator\CustomValidator(firstOption=value1)
                    }
                    childObject {
                        propertyValidators {
                            subProperty1 {
                                0 = NotEmpty
                            }
                            subProperty2 {
                                0 = NotEmpty
                            }
                        }
                    }
                }
            }
        }
    }
}