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

[FEATURE] Iterator Diff ViewHelper #988

Merged
merged 1 commit into from
Feb 25, 2016
Merged
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
52 changes: 52 additions & 0 deletions Classes/ViewHelpers/Iterator/DiffViewHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
namespace FluidTYPO3\Vhs\ViewHelpers\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 FluidTYPO3\Vhs\Traits\ArrayConsumingViewHelperTrait;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;

/**
* Computes the difference of arrays
*
* @author Thomas Deuling <typo3@coding.ms>, coding.ms
* @package Vhs
* @subpackage ViewHelpers\Iterator
*/
class DiffViewHelper extends AbstractViewHelper {

use ArrayConsumingViewHelperTrait;

/**
* Initialize
*
* @return void
*/
public function initializeArguments() {
parent::initializeArguments();

$this->registerArgument('a', 'mixed', 'First Array/Traversable/CSV', FALSE, NULL);
$this->registerArgument('b', 'mixed', 'Second Array/Traversable/CSV', TRUE);
}

/**
* @return array
*/
public function render() {
$a = $this->arguments['a'];
if (NULL === $a) {
$a = $this->renderChildren();
}

$a = $this->arrayFromArrayOrTraversableOrCSV($a);
$b = $this->arrayFromArrayOrTraversableOrCSV($this->arguments['b']);

return array_diff($a, $b);
}

}