Skip to content

Instantly share code, notes, and snippets.

@pumatertion
Created February 14, 2013 13:54
Show Gist options
  • Save pumatertion/4952982 to your computer and use it in GitHub Desktop.
Save pumatertion/4952982 to your computer and use it in GitHub Desktop.
/**
* A special action which is called if the originally intended action could
* not be called, for example if the arguments were not valid.
*
* The default implementation sets a flash message, request errors and forwards back
* to the originating action. This is suitable for most actions dealing with form input.
*
* @return string
* @api
*/
protected function errorAction() {
/**
* do we have validation errors then we set special messages.
* otherwise use the common flash message
**/
if ($this->arguments->getValidationResults()->hasErrors()) {
$errorFlashMessage = $this->getValidationErrorFlashMessage();
$this->flashMessageContainer->addMessage($errorFlashMessage);
} else {
$errorFlashMessage = $this->getErrorFlashMessage();
$this->flashMessageContainer->addMessage($errorFlashMessage);
}
$referringRequest = $this->request->getReferringRequest();
if ($referringRequest !== null) {
$subPackageKey = $referringRequest->getControllerSubpackageKey();
if ($subPackageKey !== null) {
rtrim($packageAndSubpackageKey = $referringRequest->getControllerPackageKey() . '\\' . $referringRequest->getControllerSubpackageKey(), '\\');
} else {
$packageAndSubpackageKey = $referringRequest->getControllerPackageKey();
}
$argumentsForNextController = $referringRequest->getArguments();
$argumentsForNextController['__submittedArguments'] = $this->request->getArguments();
$argumentsForNextController['__submittedArgumentValidationResults'] = $this->arguments->getValidationResults();
$this->forward($referringRequest->getControllerActionName(), $referringRequest->getControllerName(), $packageAndSubpackageKey, $argumentsForNextController);
}
$message = $this->getErrorFlashMessage()->render() . PHP_EOL;
foreach ($this->arguments->getValidationResults()->getFlattenedErrors() as $propertyPath => $errors) {
foreach ($errors as $error) {
$message .= 'Error for ' . $propertyPath . ': ' . $error->render() . PHP_EOL;
}
}
return $message;
}
/**
* A template method for displaying custom error flash messages.
* @return \TYPO3\Flow\Error\Message
*/
protected function getErrorFlashMessage() {
return new \TYPO3\Flow\Error\Error('An error occurred while trying to call %1$s->%2$s()', 1360570466, array(get_class($this), $this->actionMethodName),'Error');
}
/**
* A template method for displaying custom validation flash messages.
* @return \TYPO3\Flow\Error\Error
*/
protected function getValidationErrorFlashMessage() {
return new \TYPO3\Flow\Error\Error('Some validation failed. Please check your input data', 1360570467, array(get_class($this), $this->actionMethodName),'Validation Error');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment