Initial commit
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Context;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Condition: Is context Backend?
|
||||
*
|
||||
* A condition ViewHelper which renders the `then` child if
|
||||
* current context being rendered is BE.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* <!-- simple usage, content becomes then-child -->
|
||||
* <v:condition.context.isBackend>
|
||||
* Hooray for BE contexts!
|
||||
* </v:condition.context.isBackend>
|
||||
* <!-- extended use combined with f:then and f:else -->
|
||||
* <v:condition.context.isBackend>
|
||||
* <f:then>
|
||||
* Hooray for BE contexts!
|
||||
* </f:then>
|
||||
* <f:else>
|
||||
* Maybe FE, maybe CLI.
|
||||
* </f:else>
|
||||
* </v:condition.context.isBackend>
|
||||
*
|
||||
* @author Claus Due <claus@namelesscoder.net>
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\If\Context
|
||||
*/
|
||||
class IsBackendViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
return ('BE' === TYPO3_MODE);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Context;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Condition: Is context CLI?
|
||||
*
|
||||
* A condition ViewHelper which renders the `then` child if
|
||||
* current context being rendered is CLI.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* <!-- simple usage, content becomes then-child -->
|
||||
* <v:condition.context.isCli>
|
||||
* Hooray for CLI contexts!
|
||||
* </v:condition.context.isCli>
|
||||
* <!-- extended use combined with f:then and f:else -->
|
||||
* <v:condition.context.isCli>
|
||||
* <f:then>
|
||||
* Hooray for CLI contexts!
|
||||
* </f:then>
|
||||
* <f:else>
|
||||
* Maybe BE, maybe FE.
|
||||
* </f:else>
|
||||
* </v:condition.context.isCli>
|
||||
*
|
||||
* @author Claus Due <claus@namelesscoder.net>
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Condition\Context
|
||||
*/
|
||||
class IsCliViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
return defined('TYPO3_climode');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Context;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Context: IsDevelopment
|
||||
*
|
||||
* Returns true if current root application context is development otherwise false.
|
||||
* If no application context has been set, then the default context is production.
|
||||
*
|
||||
* #### Note about how to set the application context
|
||||
*
|
||||
* The context TYPO3 CMS runs in is specified through the environment variable TYPO3_CONTEXT.
|
||||
* It can be set by .htaccess or in the server configuration
|
||||
*
|
||||
* See: http://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Bootstrapping/Index.html#bootstrapping-context
|
||||
*
|
||||
* @author Benjamin Beck <beck@beckdigitalemedien.de>
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Condition\Context
|
||||
*/
|
||||
class IsDevelopmentViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
return GeneralUtility::getApplicationContext()->isDevelopment();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Context;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Condition: Is context Frontend?
|
||||
*
|
||||
* A condition ViewHelper which renders the `then` child if
|
||||
* current context being rendered is FE.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* <!-- simple usage, content becomes then-child -->
|
||||
* <v:condition.context.isFrontend>
|
||||
* Hooray for BE contexts!
|
||||
* </v:condition.context.isFrontend>
|
||||
* <!-- extended use combined with f:then and f:else -->
|
||||
* <v:condition.context.isFrontend>
|
||||
* <f:then>
|
||||
* Hooray for BE contexts!
|
||||
* </f:then>
|
||||
* <f:else>
|
||||
* Maybe BE, maybe CLI.
|
||||
* </f:else>
|
||||
* </v:condition.context.isFrontend>
|
||||
*
|
||||
* @author Claus Due <claus@namelesscoder.net>
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\If\Context
|
||||
*/
|
||||
class IsFrontendViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
return ('FE' === TYPO3_MODE);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Context;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Context: IsProduction
|
||||
*
|
||||
* Returns true if current root application context is production otherwise false.
|
||||
* If no application context has been set, then this is the default context.
|
||||
*
|
||||
* #### Note about how to set the application context
|
||||
*
|
||||
* The context TYPO3 CMS runs in is specified through the environment variable TYPO3_CONTEXT.
|
||||
* It can be set by .htaccess or in the server configuration
|
||||
*
|
||||
* See: http://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Bootstrapping/Index.html#bootstrapping-context
|
||||
*
|
||||
* @author Benjamin Beck <beck@beckdigitalemedien.de>
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Condition\Context
|
||||
*/
|
||||
class IsProductionViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
return GeneralUtility::getApplicationContext()->isProduction();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Context;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Context: IsProduction
|
||||
*
|
||||
* Returns true if current root application context is testing otherwise false.
|
||||
* If no application context has been set, then the default context is production.
|
||||
*
|
||||
* #### Note about how to set the application context
|
||||
*
|
||||
* The context TYPO3 CMS runs in is specified through the environment variable TYPO3_CONTEXT.
|
||||
* It can be set by .htaccess or in the server configuration
|
||||
*
|
||||
* See: http://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Bootstrapping/Index.html#bootstrapping-context
|
||||
*
|
||||
* @author Benjamin Beck <beck@beckdigitalemedien.de>
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Condition\Context
|
||||
*/
|
||||
class IsTestingViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
return GeneralUtility::getApplicationContext()->isTesting();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Form;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface;
|
||||
use TYPO3\CMS\Extbase\Reflection\ReflectionService;
|
||||
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperVariableContainer;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Form: Field Has Validator?
|
||||
*
|
||||
* Takes a property (dotted path supported) and renders the
|
||||
* then-child if the property at the given path has any
|
||||
* @validate annotation.
|
||||
*
|
||||
* @author Claus Due <claus@namelesscoder.net>
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\If\Form
|
||||
*/
|
||||
class HasValidatorViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const ALTERNATE_FORM_VIEWHELPER_CLASSNAME = 'TYPO3\\CMS\\Fluid\\ViewHelpers\\FormViewHelper';
|
||||
|
||||
/**
|
||||
* @var ReflectionService
|
||||
*/
|
||||
static protected $staticReflectionService;
|
||||
|
||||
/**
|
||||
* Render
|
||||
*
|
||||
* Renders the then-child if the property at $property of the
|
||||
* object at $object (or the associated form object if $object
|
||||
* is not specified) uses a certain @validate validator.
|
||||
*
|
||||
* @param string $property The property name, dotted path supported, to determine required
|
||||
* @param string $validatorName The class name of the Validator that indicates the property is required
|
||||
* @param DomainObjectInterface $object Optional object - if not specified, grabs the associated form object
|
||||
* @return string
|
||||
*/
|
||||
public function render($property, $validatorName = NULL, DomainObjectInterface $object = NULL) {
|
||||
return static::renderStatic(
|
||||
$this->arguments,
|
||||
$this->buildRenderChildrenClosure(),
|
||||
$this->renderingContext
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default implementation for use in compiled templates
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
* @return mixed
|
||||
*/
|
||||
static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
|
||||
|
||||
if (self::$staticReflectionService === NULL) {
|
||||
$objectManager = GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
|
||||
self::$staticReflectionService = $objectManager->get('TYPO3\CMS\Extbase\Reflection\ReflectionService');
|
||||
}
|
||||
|
||||
$property = $arguments['property'];
|
||||
$validatorName = isset($arguments['validatorName']) ? $arguments['validatorName'] : NULL;
|
||||
$object = isset($arguments['object']) ? $arguments['object'] : NULL;
|
||||
|
||||
if (NULL === $object) {
|
||||
$object = self::getFormObject($renderingContext->getViewHelperVariableContainer());
|
||||
}
|
||||
$className = get_class($object);
|
||||
if (FALSE !== strpos($property, '.')) {
|
||||
$pathSegments = explode('.', $property);
|
||||
foreach ($pathSegments as $property) {
|
||||
if (TRUE === ctype_digit($property)) {
|
||||
continue;
|
||||
}
|
||||
$annotations = self::$staticReflectionService->getPropertyTagValues($className, $property, 'var');
|
||||
$possibleClassName = array_pop($annotations);
|
||||
if (FALSE !== strpos($possibleClassName, '<')) {
|
||||
$className = array_pop(explode('<', trim($possibleClassName, '>')));
|
||||
} elseif (TRUE === class_exists($possibleClassName)) {
|
||||
$className = $possibleClassName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$annotations = self::$staticReflectionService->getPropertyTagValues($className, $property, 'validate');
|
||||
$hasEvaluated = TRUE;
|
||||
if (0 < count($annotations) && (NULL === $validatorName || TRUE === in_array($validatorName, $annotations))) {
|
||||
return static::renderStaticThenChild($arguments, $hasEvaluated);
|
||||
}
|
||||
return static::renderStaticElseChild($arguments, $hasEvaluated);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ViewHelperVariableContainer $viewHelperVariableContainer
|
||||
* @param string $formClassName
|
||||
* @return DomainObjectInterface|NULL
|
||||
*/
|
||||
static protected function getFormObject($viewHelperVariableContainer, $formClassName = 'Tx_Fluid_ViewHelpers_FormViewHelper') {
|
||||
if (TRUE === $viewHelperVariableContainer->exists($formClassName, 'formObject')) {
|
||||
return $viewHelperVariableContainer->get($formClassName, 'formObject');
|
||||
}
|
||||
if (self::ALTERNATE_FORM_VIEWHELPER_CLASSNAME !== $formClassName) {
|
||||
return self::getFormObject($viewHelperVariableContainer, self::ALTERNATE_FORM_VIEWHELPER_CLASSNAME);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Form;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface;
|
||||
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
|
||||
/**
|
||||
* ### Is Field Required ViewHelper (condition)
|
||||
*
|
||||
* Takes a property (dotted path supported) and renders the
|
||||
* then-child if the property at the given path has an
|
||||
* @validate NotEmpty annotation
|
||||
*
|
||||
* @author Claus Due <claus@namelesscoder.net>
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Condition\Form
|
||||
*/
|
||||
class IsRequiredViewHelper extends HasValidatorViewHelper {
|
||||
|
||||
/**
|
||||
* Default implementation for use in compiled templates
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
* @return mixed
|
||||
*/
|
||||
static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
|
||||
$arguments['validatorName'] = 'NotEmpty';
|
||||
return parent::renderStatic($arguments, $renderChildrenClosure, $renderingContext);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Iterator;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject;
|
||||
use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface;
|
||||
use TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage;
|
||||
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
|
||||
* haystack contains needle value.
|
||||
*
|
||||
* ### Example:
|
||||
*
|
||||
* {v:condition.iterator.contains(needle: 'foo', haystack: {0: 'foo'}, then: 'yes', else: 'no')}
|
||||
*
|
||||
* @author Claus Due <claus@namelesscoder.net>
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Condition\Iterator
|
||||
*/
|
||||
class ContainsViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
$this->registerArgument('needle', 'mixed', 'Needle to search for in haystack', TRUE);
|
||||
$this->registerArgument('haystack', 'mixed', 'Haystack in which to look for needle', TRUE);
|
||||
$this->registerArgument('considerKeys', 'boolean', 'Tell whether to consider keys in the search assuming haystack is an array.', FALSE, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
return FALSE !== self::assertHaystackHasNeedle($arguments['haystack'], $arguments['needle'], $arguments);;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $index
|
||||
* @param array $arguments
|
||||
* @return mixed
|
||||
*/
|
||||
static protected function getNeedleAtIndex($index, $arguments) {
|
||||
if (0 > $index) {
|
||||
return NULL;
|
||||
}
|
||||
$haystack = $arguments['haystack'];
|
||||
$asArray = array();
|
||||
if (TRUE === is_array($haystack)) {
|
||||
$asArray = $haystack;
|
||||
} elseif (TRUE === $haystack instanceof LazyObjectStorage) {
|
||||
/** @var $haystack LazyObjectStorage */
|
||||
$asArray = $haystack->toArray();
|
||||
} elseif (TRUE === $haystack instanceof ObjectStorage) {
|
||||
/** @var $haystack ObjectStorage */
|
||||
$asArray = $haystack->toArray();
|
||||
} elseif (TRUE === $haystack instanceof QueryResult) {
|
||||
/** @var $haystack QueryResult */
|
||||
$asArray = $haystack->toArray();
|
||||
} elseif (TRUE === is_string($haystack)) {
|
||||
$asArray = str_split($haystack);
|
||||
}
|
||||
return (TRUE === isset($asArray[$index]) ? $asArray[$index] : FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $haystack
|
||||
* @param mixed $needle
|
||||
* @param array $arguments
|
||||
* @return boolean|integer
|
||||
*/
|
||||
static protected function assertHaystackHasNeedle($haystack, $needle, $arguments) {
|
||||
if (TRUE === is_array($haystack)) {
|
||||
return self::assertHaystackIsArrayAndHasNeedle($haystack, $needle, $arguments);
|
||||
} elseif ($haystack instanceof LazyObjectStorage) {
|
||||
return self::assertHaystackIsObjectStorageAndHasNeedle($haystack, $needle);
|
||||
} elseif ($haystack instanceof ObjectStorage) {
|
||||
return self::assertHaystackIsObjectStorageAndHasNeedle($haystack, $needle);
|
||||
} elseif ($haystack instanceof QueryResult) {
|
||||
return self::assertHaystackIsQueryResultAndHasNeedle($haystack, $needle);
|
||||
} elseif (TRUE === is_string($haystack)) {
|
||||
return strpos($haystack, $needle);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $haystack
|
||||
* @param mixed $needle
|
||||
* @return boolean|integer
|
||||
*/
|
||||
static protected function assertHaystackIsQueryResultAndHasNeedle($haystack, $needle) {
|
||||
if (TRUE === $needle instanceof DomainObjectInterface) {
|
||||
/** @var $needle DomainObjectInterface */
|
||||
$needle = $needle->getUid();
|
||||
}
|
||||
foreach ($haystack as $index => $candidate) {
|
||||
/** @var $candidate DomainObjectInterface */
|
||||
if ((integer) $candidate->getUid() === (integer) $needle) {
|
||||
return $index;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $haystack
|
||||
* @param mixed $needle
|
||||
* @return boolean|integer
|
||||
*/
|
||||
static protected function assertHaystackIsObjectStorageAndHasNeedle($haystack, $needle) {
|
||||
$index = 0;
|
||||
/** @var $candidate DomainObjectInterface */
|
||||
if (TRUE === $needle instanceof AbstractDomainObject) {
|
||||
$needle = $needle->getUid();
|
||||
}
|
||||
foreach ($haystack as $candidate) {
|
||||
if ((integer) $candidate->getUid() === (integer) $needle) {
|
||||
return $index;
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $haystack
|
||||
* @param mixed $needle
|
||||
* @param array $arguments
|
||||
* @return boolean|integer
|
||||
*/
|
||||
static protected function assertHaystackIsArrayAndHasNeedle($haystack, $needle, $arguments) {
|
||||
if (FALSE === $needle instanceof DomainObjectInterface) {
|
||||
if (TRUE === (boolean) $arguments['considerKeys']) {
|
||||
$result = (boolean) (FALSE !== array_search($needle, $haystack) || TRUE === isset($haystack[$needle]));
|
||||
} else {
|
||||
$result = array_search($needle, $haystack);
|
||||
}
|
||||
return $result;
|
||||
} else {
|
||||
/** @var $needle DomainObjectInterface */
|
||||
foreach ($haystack as $index => $straw) {
|
||||
/** @var $straw DomainObjectInterface */
|
||||
if ((integer) $straw->getUid() === (integer) $needle->getUid()) {
|
||||
return $index;
|
||||
}
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $haystack
|
||||
* @param mixed $needle
|
||||
* @return boolean|integer
|
||||
*/
|
||||
static protected function assertHaystackIsStringAndHasNeedle($haystack, $needle) {
|
||||
return strpos($haystack, $needle);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Page;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use FluidTYPO3\Vhs\Service\PageSelectService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Condition: Page has subpages
|
||||
*
|
||||
* A condition ViewHelper which renders the `then` child if
|
||||
* current page or page with provided UID has subpages. By default
|
||||
* disabled subpages are considered non existent which can be overridden
|
||||
* by setting $includeHidden to TRUE. To include pages that are hidden
|
||||
* in menus set $showHiddenInMenu to TRUE.
|
||||
*
|
||||
* @author Björn Fromme <fromme@dreipunktnull.com>, dreipunktnull
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Condition\Page
|
||||
*/
|
||||
class HasSubpagesViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* @var PageSelectService
|
||||
*/
|
||||
static protected $pageSelect;
|
||||
|
||||
/**
|
||||
* @param PageSelectService $pageSelect
|
||||
* @return void
|
||||
*/
|
||||
static public function setPageSelectService(PageSelectService $pageSelect) {
|
||||
self::$pageSelect = $pageSelect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('pageUid', 'integer', 'value to check', FALSE, NULL);
|
||||
$this->registerArgument('includeHidden', 'boolean', 'include hidden pages', FALSE, FALSE);
|
||||
$this->registerArgument('showHiddenInMenu', 'boolean', 'include pages hidden in menu', FALSE, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
$pageUid = $arguments['pageUid'];
|
||||
$includeHidden = $arguments['includeHidden'];
|
||||
$showHiddenInMenu = $arguments['showHiddenInMenu'];
|
||||
|
||||
if (NULL === $pageUid || TRUE === empty($pageUid) || 0 === intval($pageUid)) {
|
||||
$pageUid = $GLOBALS['TSFE']->id;
|
||||
}
|
||||
|
||||
if (self::$pageSelect === NULL) {
|
||||
$objectManager = GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
|
||||
self::$pageSelect = $objectManager->get('FluidTYPO3\Vhs\Service\PageSelectService');
|
||||
}
|
||||
|
||||
$menu = self::$pageSelect->getMenu($pageUid, array(), '', $showHiddenInMenu);
|
||||
$pageHasSubPages = (0 < count($menu));
|
||||
return TRUE === $pageHasSubPages;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Page;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use TYPO3\CMS\Frontend\Page\PageRepository;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Condition: Page is child page
|
||||
*
|
||||
* Condition ViewHelper which renders the `then` child if current
|
||||
* page or page with provided UID is a child of some other page in
|
||||
* the page tree. If $respectSiteRoot is set to TRUE root pages are
|
||||
* never considered child pages even if they are.
|
||||
*
|
||||
* @author Björn Fromme <fromme@dreipunktnull.com>, dreipunktnull
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Condition\Page
|
||||
*/
|
||||
class IsChildPageViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('pageUid', 'integer', 'value to check', FALSE, NULL);
|
||||
$this->registerArgument('respectSiteRoot', 'boolean', 'value to check', FALSE, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
$pageUid = $arguments['pageUid'];
|
||||
$respectSiteRoot = $arguments['respectSiteRoot'];
|
||||
|
||||
if (NULL === $pageUid || TRUE === empty($pageUid) || 0 === intval($pageUid)) {
|
||||
$pageUid = $GLOBALS['TSFE']->id;
|
||||
}
|
||||
$pageSelect = new PageRepository();
|
||||
$page = $pageSelect->getPage($pageUid);
|
||||
|
||||
if (TRUE === (boolean) $respectSiteRoot && TRUE === isset($page['is_siteroot']) && TRUE === (boolean) $page['is_siteroot']) {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE === isset($page['pid']) && 0 < $page['pid'];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Page;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Condition: Is current language
|
||||
*
|
||||
* A condition ViewHelper which renders the `then` child if
|
||||
* current language matches the provided language uid or language
|
||||
* title. When using language titles like 'de' it is required to
|
||||
* provide a default title to distinguish between the standard
|
||||
* and a non existing language.
|
||||
*
|
||||
* @author Björn Fromme <fromme@dreipunktnull.com>, dreipunktnull
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Condition\Page
|
||||
*/
|
||||
class IsLanguageViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('language', 'string', 'language to check', TRUE);
|
||||
$this->registerArgument('defaultTitle', 'string', 'title of the default language', FALSE, 'en');
|
||||
}
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
$language = $arguments['language'];
|
||||
$defaultTitle = $arguments['defaultTitle'];
|
||||
|
||||
$currentLanguageUid = $GLOBALS['TSFE']->sys_language_uid;
|
||||
if (TRUE === is_numeric($language)) {
|
||||
$languageUid = intval($language);
|
||||
} else {
|
||||
$row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('uid', 'sys_language', "title='" . $language . "'");
|
||||
if (FALSE !== $row) {
|
||||
$languageUid = intval($row['uid']);
|
||||
} else {
|
||||
if ((string) $language === $defaultTitle) {
|
||||
$languageUid = $currentLanguageUid;
|
||||
} else {
|
||||
$languageUid = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $languageUid === $currentLanguageUid;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\String;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Condition: String contains substring
|
||||
*
|
||||
* Condition ViewHelper which renders the `then` child if provided
|
||||
* string $haystack contains provided string $needle.
|
||||
*
|
||||
* @author Björn Fromme <fromme@dreipunktnull.com>, dreipunktnull
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Condition\String
|
||||
*/
|
||||
class ContainsViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('haystack', 'string', 'haystack', TRUE);
|
||||
$this->registerArgument('needle', 'string', 'need', TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
return FALSE !== strpos($arguments['haystack'], $arguments['needle']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\String;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Condition: String is lowercase
|
||||
*
|
||||
* Condition ViewHelper which renders the `then` child if provided
|
||||
* string is lowercase. By default only the first letter is tested.
|
||||
* To test the full string set $fullString to TRUE.
|
||||
*
|
||||
* @author Björn Fromme <fromme@dreipunktnull.com>, dreipunktnull
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Condition\String
|
||||
*/
|
||||
class IsLowercaseViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('string', 'string', 'string to check', TRUE);
|
||||
$this->registerArgument('fullString', 'string', 'need', FALSE, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
if (TRUE === $arguments['fullString']) {
|
||||
$result = ctype_lower($arguments['string']);
|
||||
} else {
|
||||
$result = ctype_lower(substr($arguments['string'], 0, 1));
|
||||
}
|
||||
return TRUE === $result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\String;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Condition: Value is numeric
|
||||
*
|
||||
* Condition ViewHelper which renders the `then` child if provided
|
||||
* value is numeric.
|
||||
*
|
||||
* @author Björn Fromme <fromme@dreipunktnull.com>, dreipunktnull
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Condition\String
|
||||
*/
|
||||
class IsNumericViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('value', 'mixed', 'value to check', TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
return TRUE === ctype_digit($arguments['value']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\String;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Condition: String is lowercase
|
||||
*
|
||||
* Condition ViewHelper which renders the `then` child if provided
|
||||
* string is uppercase. By default only the first letter is tested.
|
||||
* To test the full string set $fullString to TRUE.
|
||||
*
|
||||
* @author Björn Fromme <fromme@dreipunktnull.com>, dreipunktnull
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Condition\String
|
||||
*/
|
||||
class IsUppercaseViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('string', 'string', 'string to check', TRUE);
|
||||
$this->registerArgument('fullString', 'string', 'need', FALSE, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
if (TRUE === $arguments['fullString']) {
|
||||
$result = ctype_upper($arguments['string']);
|
||||
} else {
|
||||
$result = ctype_upper(substr($arguments['string'], 0, 1));
|
||||
}
|
||||
return TRUE === $result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\String;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use FluidTYPO3\Vhs\Traits\TemplateVariableViewHelperTrait;
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Condition: String matches regular expression
|
||||
*
|
||||
* Condition ViewHelper which renders the `then` child if provided
|
||||
* string matches provided regular expression. $matches array containing
|
||||
* the results can be made available by providing a template variable
|
||||
* name with argument $as.
|
||||
*
|
||||
* @author Björn Fromme <fromme@dreipunktnull.com>, dreipunktnull
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Condition\String
|
||||
*/
|
||||
class PregViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use TemplateVariableViewHelperTrait;
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('pattern', 'string', 'regex pattern to match string against', TRUE);
|
||||
$this->registerArgument('string', 'string', 'string to match with the regex pattern', TRUE);
|
||||
$this->registerArgument('global', 'boolean', 'match global', FALSE, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
$matches = array();
|
||||
if (TRUE === (boolean) $arguments['global']) {
|
||||
preg_match_all($arguments['pattern'], $arguments['string'], $matches, PREG_SET_ORDER);
|
||||
} else {
|
||||
preg_match($arguments['pattern'], $arguments['string'], $matches);
|
||||
}
|
||||
return 0 < count($matches);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)) {
|
||||
$content = $this->renderThenChild();
|
||||
} else {
|
||||
$content = $this->renderElseChild();
|
||||
}
|
||||
return $this->renderChildrenWithVariableOrReturnInput($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext
|
||||
* @return mixed
|
||||
*/
|
||||
static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext) {
|
||||
$hasEvaluated = TRUE;
|
||||
$content = '';
|
||||
if (static::evaluateCondition($arguments)) {
|
||||
$result = static::renderStaticThenChild($arguments, $hasEvaluated);
|
||||
if ($hasEvaluated) {
|
||||
$content = $result;
|
||||
}
|
||||
} else {
|
||||
$result = static::renderStaticElseChild($arguments, $hasEvaluated);
|
||||
if ($hasEvaluated) {
|
||||
$content = $result;
|
||||
}
|
||||
}
|
||||
return self::renderChildrenWithVariableOrReturnInputStatic($content, $arguments['as'], $renderingContext, $renderChildrenClosure);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Type;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Condition: Type of value is array
|
||||
*
|
||||
* Condition ViewHelper which renders the `then` child if type of
|
||||
* provided value is array.
|
||||
*
|
||||
* @author Björn Fromme <fromme@dreipunktnull.com>, dreipunktnull
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Condition\Type
|
||||
*/
|
||||
class IsArrayViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('value', 'string', 'value to check', TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
return (isset($arguments['value']) && (TRUE === is_array($arguments['value'])));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Type;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Condition: Type of value is a boolean
|
||||
*
|
||||
* Condition ViewHelper which renders the `then` child if type of
|
||||
* provided value is a boolean.
|
||||
*
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Condition\Type
|
||||
*/
|
||||
class IsBooleanViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('value', 'mixed', 'value to check', TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
return TRUE === is_bool($arguments['value']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Type;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject;
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Condition: Value is a domain object
|
||||
*
|
||||
* Condition ViewHelper which renders the `then` child if provided
|
||||
* value is a domain object, i.e. it inherits from extbase's base
|
||||
* class
|
||||
*
|
||||
* @author Björn Fromme <fromme@dreipunktnull.com>, dreipunktnull
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Condition\Type
|
||||
*/
|
||||
class IsDomainObjectViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('value', 'mixed', 'value to check', TRUE);
|
||||
$this->registerArgument('fullString', 'string', 'need', FALSE, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
return TRUE === $arguments['value'] instanceof AbstractDomainObject;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Type;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Condition: Type of value is float
|
||||
*
|
||||
* Condition ViewHelper which renders the `then` child if type of
|
||||
* provided value is float.
|
||||
*
|
||||
* @author Björn Fromme <fromme@dreipunktnull.com>, dreipunktnull
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Condition\Type
|
||||
*/
|
||||
class IsFloatViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('value', 'mixed', 'value to check', TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
return TRUE === is_float($arguments['value']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Type;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Condition: Value is an instance of a class
|
||||
*
|
||||
* Condition ViewHelper which renders the `then` child if provided
|
||||
* value is an instance of provided class name.
|
||||
*
|
||||
* @author Björn Fromme <fromme@dreipunktnull.com>, dreipunktnull
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Condition\Type
|
||||
*/
|
||||
class IsInstanceOfViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('value', 'mixed', 'value to check', TRUE);
|
||||
$this->registerArgument('class', 'mixed', 'className to check against', TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
return TRUE === $arguments['value'] instanceof $arguments['class'];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Type;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Condition: Type of value is integer
|
||||
*
|
||||
* Condition ViewHelper which renders the `then` child if type of
|
||||
* provided value is integer.
|
||||
*
|
||||
* @author Björn Fromme <fromme@dreipunktnull.com>, dreipunktnull
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Condition\Type
|
||||
*/
|
||||
class IsIntegerViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('value', 'mixed', 'value to check', TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
return TRUE === is_integer($arguments['value']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Type;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Condition: Value is an object
|
||||
*
|
||||
* Condition ViewHelper which renders the `then` child if provided
|
||||
* value is an object.
|
||||
*
|
||||
* @author Björn Fromme <fromme@dreipunktnull.com>, dreipunktnull
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Type\Type
|
||||
*/
|
||||
class IsObjectViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('value', 'mixed', 'value to check', TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
return TRUE === is_object($arguments['value']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Type;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Condition: Value is a query result
|
||||
*
|
||||
* Condition ViewHelper which renders the `then` child if provided
|
||||
* value is an extbase query result
|
||||
*
|
||||
* @author Björn Fromme <fromme@dreipunktnull.com>, dreipunktnull
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Condition\Type
|
||||
*/
|
||||
class IsQueryResultViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('value', 'mixed', 'value to check', TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
return TRUE === $arguments['value'] instanceof QueryResultInterface;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Type;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Condition: Type of value is string
|
||||
*
|
||||
* Condition ViewHelper which renders the `then` child if type of
|
||||
* provided value is string.
|
||||
*
|
||||
* @author Björn Fromme <fromme@dreipunktnull.com>, dreipunktnull
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Condition\Type
|
||||
*/
|
||||
class IsStringViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('value', 'mixed', 'value to check', TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
return TRUE === is_string($arguments['value']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Type;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Condition: Value implements interface Traversable
|
||||
*
|
||||
* Condition ViewHelper which renders the `then` child if provided
|
||||
* value implements interface Traversable
|
||||
*
|
||||
* @author Björn Fromme <fromme@dreipunktnull.com>, dreipunktnull
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Condition\Type
|
||||
*/
|
||||
class IsTraversableViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('value', 'mixed', 'value to check', TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
return TRUE === $arguments['value'] instanceof \Traversable;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Variable;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Condition: Value is NULL
|
||||
*
|
||||
* Condition ViewHelper which renders the `then` child if provided
|
||||
* value is NULL.
|
||||
*
|
||||
* @author Björn Fromme <fromme@dreipunktnull.com>, dreipunktnull
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\If\Var
|
||||
*/
|
||||
class IsNullViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('value', 'string', 'value to check', TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
|
||||
* @return bool
|
||||
*/
|
||||
static protected function evaluateCondition($arguments = NULL) {
|
||||
return NULL === $arguments['value'];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Variable;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
use FluidTYPO3\Vhs\Traits\ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* ### Variable: Isset
|
||||
*
|
||||
* Renders the `then` child if the variable name given in
|
||||
* the `name` argument exists in the template. The value
|
||||
* can be zero, NULL or an empty string - but the ViewHelper
|
||||
* will still return TRUE if the variable exists.
|
||||
*
|
||||
* Combines well with dynamic variable names:
|
||||
*
|
||||
* <!-- if {variableContainingVariableName} is "foo" this checks existence of {foo} -->
|
||||
* <v:condition.variable.isset name="{variableContainingVariableName}">...</v:condition.variable.isset>
|
||||
* <!-- if {suffix} is "Name" this checks existence of "variableName" -->
|
||||
* <v:condition.variable.isset name="variable{suffix}">...</v:condition.variable.isset>
|
||||
* <!-- outputs value of {foo} if {bar} is defined -->
|
||||
* {foo -> v:condition.variable.isset(name: bar)}
|
||||
*
|
||||
* @author Claus Due <claus@namelesscoder.net>
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Condition\Variable
|
||||
*/
|
||||
class IssetViewHelper extends AbstractConditionViewHelper {
|
||||
|
||||
use ConditionViewHelperTrait;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('name', 'string', 'name of the variable', TRUE);
|
||||
}
|
||||
/**
|
||||
* Render
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render() {
|
||||
return static::renderStatic(
|
||||
$this->arguments,
|
||||
$this->buildRenderChildrenClosure(),
|
||||
$this->renderingContext
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default implementation for use in compiled templates
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext
|
||||
* @return mixed
|
||||
*/
|
||||
static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
|
||||
$hasEvaluated = TRUE;
|
||||
|
||||
if (TRUE === $renderingContext->getTemplateVariableContainer()->exists($arguments['name'])) {
|
||||
$result = static::renderStaticThenChild($arguments, $hasEvaluated);
|
||||
if ($hasEvaluated) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $renderChildrenClosure();
|
||||
} else {
|
||||
$result = static::renderStaticElseChild($arguments, $hasEvaluated);
|
||||
if ($hasEvaluated) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user