Skip to content

Commit

Permalink
[BUGFIX] Remove usage of ConditionViewHelperTrait
Browse files Browse the repository at this point in the history
Fixes compiled rendering issues with various condition ViewHelpers.
  • Loading branch information
NamelessCoder committed Oct 22, 2017
1 parent 7669d06 commit 0e4a73c
Show file tree
Hide file tree
Showing 31 changed files with 49 additions and 280 deletions.
130 changes: 1 addition & 129 deletions Classes/Traits/ConditionViewHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,137 +8,9 @@
* LICENSE.md file that was distributed with this source code.
*/

use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;

/**
* This trait can be used by viewhelpers that generate image tags
* to add srcsets based to the imagetag for better responsiveness
* @deprecated no longer required since TYPO3 7.6
*/
trait ConditionViewHelperTrait
{

/**
* renders <f:then> child if $condition is true, otherwise renders <f:else> child.
*
* @return string the rendered string
* @api
*/
public function render()
{
if (static::evaluateCondition($this->arguments)) {
return $this->renderThenChild();
} else {
return $this->renderElseChild();
}
}

/**
* Default implementation for use in compiled templates
*
* TODO: remove at some point, because this is only here for legacy reasons.
* the AbstractConditionViewHelper in 6.2.* doesn't have a default render
* method. 7.2+ on the other hand provides basically exactly this method here
* luckily it's backwards compatible out of the box.
* tl;dr -> remove after expiration of support for anything below 7.2
*
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return mixed
*/
static public function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
$hasEvaluated = true;
if (static::evaluateCondition($arguments)) {
$result = static::renderStaticThenChild($arguments, $hasEvaluated);
if ($hasEvaluated) {
return $result;
}

return $renderChildrenClosure();
} else {
$result = static::renderStaticElseChild($arguments, $hasEvaluated);
if ($hasEvaluated) {
return $result;
}
}

return '';
}

/**
* Statically evalute "then" children.
* The "$hasEvaluated" argument is there to distinguish the case that "then" returned NULL or was not evaluated.
*
* TODO: remove at some point, because this is only here for legacy reasons.
* the AbstractConditionViewHelper in 6.2.* doesn't have a default render
* method. 7.2+ on the other hand provides basically exactly this method here
* luckily it's backwards compatible out of the box.
* tl;dr -> remove after expiration of support for anything below 7.2
*
* @param array $arguments ViewHelper arguments
* @param bool $hasEvaluated Can be used to check if the "then" child was actually evaluated by this method.
* @return string
*/
static protected function renderStaticThenChild($arguments, &$hasEvaluated)
{
if (isset($arguments['then'])) {
return $arguments['then'];
}
if (isset($arguments['__thenClosure'])) {
$thenClosure = $arguments['__thenClosure'];
return $thenClosure();
} elseif (isset($arguments['__elseClosure'])) {
return '';
}

$hasEvaluated = false;
}

/**
* Statically evalute "else" children.
* The "$hasEvaluated" argument is there to distinguish the case that "else" returned NULL or was not evaluated.
*
* TODO: remove at some point, because this is only here for legacy reasons.
* the AbstractConditionViewHelper in 6.2.* doesn't have a default render
* method. 7.2+ on the other hand provides basically exactly this method here
* luckily it's backwards compatible out of the box.
* tl;dr -> remove after expiration of support for anything below 7.2
*
* @param array $arguments ViewHelper arguments
* @param bool $hasEvaluated Can be used to check if the "else" child was actually evaluated by this method.
* @return string
*/
static protected function renderStaticElseChild($arguments, &$hasEvaluated)
{
if (isset($arguments['else'])) {
return $arguments['else'];
}
if (isset($arguments['__elseClosure'])) {
$elseClosure = $arguments['__elseClosure'];
return $elseClosure();
}

$hasEvaluated = false;
}

/**
* This method decides if the condition is TRUE or FALSE.
*
* TODO: remove at some point, because this is only here for legacy reasons.
* the AbstractConditionViewHelper in 6.2.* doesn't have a default render
* method. 7.2+ on the other hand provides basically exactly this method here
* luckily it's backwards compatible out of the box.
* tl;dr -> remove after expiration of support for anything below 7.2
*
* @param array $arguments
* @return bool
*/
static protected function evaluateCondition($arguments = null)
{
return (isset($arguments['condition']) && $arguments['condition']);
}
}
4 changes: 0 additions & 4 deletions Classes/ViewHelpers/Condition/Context/IsBackendViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/

use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;

/**
* ### Condition: Is context Backend?
Expand All @@ -35,9 +34,6 @@
*/
class IsBackendViewHelper extends AbstractConditionViewHelper
{

use ConditionViewHelperTrait;

/**
* @param array $arguments
* @return bool
Expand Down
4 changes: 0 additions & 4 deletions Classes/ViewHelpers/Condition/Context/IsCliViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/

use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;

/**
* ### Condition: Is context CLI?
Expand All @@ -35,9 +34,6 @@
*/
class IsCliViewHelper extends AbstractConditionViewHelper
{

use ConditionViewHelperTrait;

/**
* @param array $arguments
* @return bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;

use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;

/**
* ### Context: IsDevelopment
*
Expand All @@ -28,9 +26,6 @@
*/
class IsDevelopmentViewHelper extends AbstractConditionViewHelper
{

use ConditionViewHelperTrait;

/**
* @param array $arguments
* @return bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/

use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;

/**
* ### Condition: Is context Frontend?
Expand All @@ -35,9 +34,6 @@
*/
class IsFrontendViewHelper extends AbstractConditionViewHelper
{

use ConditionViewHelperTrait;

/**
* @param array $arguments
* @return bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;

/**
* ### Context: IsProduction
Expand All @@ -27,9 +26,6 @@
*/
class IsProductionViewHelper extends AbstractConditionViewHelper
{

use ConditionViewHelperTrait;

/**
* @param array $arguments
* @return bool
Expand Down
4 changes: 0 additions & 4 deletions Classes/ViewHelpers/Condition/Context/IsTestingViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;

/**
* ### Context: IsProduction
Expand All @@ -27,9 +26,6 @@
*/
class IsTestingViewHelper extends AbstractConditionViewHelper
{

use ConditionViewHelperTrait;

/**
* @param array $arguments
* @return bool
Expand Down
4 changes: 0 additions & 4 deletions Classes/ViewHelpers/Condition/Form/HasValidatorViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use TYPO3\CMS\Extbase\Reflection\ReflectionService;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
use TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperVariableContainer;
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
use TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper;

/**
Expand All @@ -26,9 +25,6 @@
*/
class HasValidatorViewHelper extends AbstractConditionViewHelper
{

use ConditionViewHelperTrait;

/**
* @var string
*/
Expand Down
4 changes: 0 additions & 4 deletions Classes/ViewHelpers/Condition/Iterator/ContainsViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use TYPO3\CMS\Extbase\Persistence\Generic\QueryResult;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;

/**
* Condition ViewHelper. Renders the then-child if Iterator/array
Expand All @@ -26,9 +25,6 @@
*/
class ContainsViewHelper extends AbstractConditionViewHelper
{

use ConditionViewHelperTrait;

/**
* Initialize arguments
*/
Expand Down
4 changes: 0 additions & 4 deletions Classes/ViewHelpers/Condition/Page/HasSubpagesViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;

/**
* ### Condition: Page has subpages
Expand All @@ -25,9 +24,6 @@
*/
class HasSubpagesViewHelper extends AbstractConditionViewHelper
{

use ConditionViewHelperTrait;

/**
* @var PageService
*/
Expand Down
4 changes: 0 additions & 4 deletions Classes/ViewHelpers/Condition/Page/IsChildPageViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
use TYPO3\CMS\Frontend\Page\PageRepository;
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;

/**
* ### Condition: Page is child page
Expand All @@ -22,9 +21,6 @@
*/
class IsChildPageViewHelper extends AbstractConditionViewHelper
{

use ConditionViewHelperTrait;

/**
* Initialize arguments
*/
Expand Down
4 changes: 0 additions & 4 deletions Classes/ViewHelpers/Condition/Page/IsLanguageViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/

use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;

/**
* ### Condition: Is current language
Expand All @@ -22,9 +21,6 @@
*/
class IsLanguageViewHelper extends AbstractConditionViewHelper
{

use ConditionViewHelperTrait;

/**
* Initialize arguments
*/
Expand Down
4 changes: 0 additions & 4 deletions Classes/ViewHelpers/Condition/String/ContainsViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/

use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;

/**
* ### Condition: String contains substring
Expand All @@ -19,9 +18,6 @@
*/
class ContainsViewHelper extends AbstractConditionViewHelper
{

use ConditionViewHelperTrait;

/**
* Initialize arguments
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/

use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;

/**
* ### Condition: String is lowercase
Expand All @@ -20,9 +19,6 @@
*/
class IsLowercaseViewHelper extends AbstractConditionViewHelper
{

use ConditionViewHelperTrait;

/**
* Initialize arguments
*/
Expand Down
4 changes: 0 additions & 4 deletions Classes/ViewHelpers/Condition/String/IsNumericViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/

use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;

/**
* ### Condition: Value is numeric
Expand All @@ -19,9 +18,6 @@
*/
class IsNumericViewHelper extends AbstractConditionViewHelper
{

use ConditionViewHelperTrait;

/**
* Initialize arguments
*/
Expand Down
Loading

0 comments on commit 0e4a73c

Please sign in to comment.