Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update class HasErrorViewHelper for TYPO3 9.5 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions Classes/ViewHelpers/Condition/Form/HasErrorViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,43 @@
namespace WapplerSystems\ExtbaseFluidFormValidation\ViewHelpers\Condition\Form;


use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;

/**
* Class HasErrorViewHelper
*
* Hätte diese gerne mit AbstractConditionViewHelper realisiert, aber da gibt es wegen der static Methoden Probleme auf den controllerContext zurückzugreifen
*
* @package WapplerSystems\ExtbaseFluidFormValidation\ViewHelpers\Condition\Form
* @package Zwo3\Klimatour\ViewHelpers\Form
*/
class HasErrorViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
{
class HasErrorViewHelper extends AbstractViewHelper {

public function initializeArguments()
{
$this->registerArgument('for', 'string', 'The property', true);
$this->registerArgument('then', 'string', 'The class to add', true);
}

/**
* @param string $for
* @param string $then
* @return string
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return mixed
*/
public function render($for = '', $then = '')
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{

$validationResults = $this->controllerContext->getRequest()->getOriginalRequestMappingResults();
$controllerContext = $renderingContext->getcontrollerContext();
$validationResults = $controllerContext->getRequest()->getOriginalRequestMappingResults();
$for = $arguments['for'];
$then = $arguments['then'];

if ($validationResults !== null && $for !== '') {
$validationResults = $validationResults->forProperty($for);
}

if ($validationResults->hasErrors()) {
return $then;
}
return "";
}


}
}