[TYPO3-50-general] Validator: unique users

Steffen Ritter info at rs-websystems.de
Mon Feb 7 10:34:41 CET 2011


Am 07.02.2011 09:15, schrieb Julian Kleinhans:
> Hi Bastian,
>
> thanks for your reply!
> The Problem here is that i must use the flashMessageContainer.. then i
> have some messages in the "form.errors" viewhelper and this one in the
> flashMessageConatiner.. it was beatifull if i can add my own errors like
>
> if ($this->userRepository->findOneByUsername($username) !== NULL) {
> $this->error->add('myForm', 'username', 'Username already used');
> $this->redirect(...);
> }
>

This is possible :) if have this in a controller... I could give you 
another one, which also allows property.subproperty.subsubproperty syntax...



protected function createError($object, $property, $string) {
	$errors = $this->argumentsMappingResults->getErrors();
	$newError = t3lib_div::makeInstance('Tx_Extbase_Validation_Error', 
$string, time());
	if(!isset($errors[$object])) {
		$errors[$object] = 
t3lib_div::makeInstance('Tx_Extbase_MVC_Controller_ArgumentError', $object);
		$this->argumentsMappingResults->addError($errors[$object], $object);
	}
	$objectErrors = $errors[$object]->getErrors();
	if(!isset($objectErrors[$property])) {
		$propertyError = 
t3lib_div::makeInstance('Tx_Extbase_Validation_PropertyError',  $property);
		$errors[$object]->addErrors(array($property => $propertyError));
	} else {
		$propertyError = $objectErrors[$property];
	}
	$propertyError->addErrors(array($newError));
}

regards

Steffen


More information about the TYPO3-project-5_0-general mailing list