ew_base/Classes/ViewHelpers/Condition/InArrayViewHelper.php
Sebastian Fischer 5319bd35a5 First commit
2024-02-09 17:13:28 +01:00

42 lines
1.1 KiB
PHP
Executable File

<?php
namespace Evoweb\EwBase\ViewHelpers\Condition;
/*
* 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 TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
/**
* ### Condition: Array contains element
*
* Condition ViewHelper which renders the `then` child if provided
* string $haystack contains provided string $needle.
*/
class InArrayViewHelper extends AbstractConditionViewHelper
{
/**
* Initialize arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('haystack', 'array', 'haystack', true);
$this->registerArgument('needle', 'mixed', 'needle', true);
}
/**
* @param array $arguments
* @return bool
*/
protected static function evaluateCondition($arguments = null)
{
$array = $arguments['haystack']->toArray();
return in_array($arguments['needle'], $array);
}
}