PHP Class FluidTYPO3\Vhs\ViewHelpers\Iterator\ExtractViewHelper

Loop through the iterator and extract a key, optionally join the results if more than one value is found. #### Extract values from an array by key The extbase version of indexed_search returns an array of the previous search, which cannot easily be shown in the input field of the result page. This can be solved. #### Input from extbase version of indexed_search"> array( 0 => array( 'sword' => 'firstWord', 'oper' => 'AND' ), 1 => array( 'sword' => 'secondWord', 'oper' => 'AND' ), 3 => array( 'sword' => 'thirdWord', 'oper' => 'AND' ) ) Show the previous search words in the search form of the result page: #### Example #### Get the names of several users Provided we have a bunch of FrontendUsers and we need to show their firstname combined into a string:

Welcome {frontendUsers -> v:iterator.extract(key: 'firstname') -> v:iterator.implode(glue: ', ')}

#### Output

Welcome Peter, Paul, Marry

#### Complex example {anArray->v:iterator.extract(path: 'childProperty.secondNestedChildObject')->v:iterator.sort(direction: 'DESC', sortBy: 'propertyOnSecondChild')->v:iterator.slice(length: 10)->v:iterator.extract(key: 'uid')}
Author: Andreas Lappe ([email protected])
Inheritance: extends TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
ファイルを表示 Open project: fluidtypo3/vhs Class Usage Examples

Public Methods

Method Description
extractByKey ( Traversable $iterator, string $key ) : mixed Extract by key
flattenArray ( array $content, array $flattened = null ) : array Flatten the result structure, to iterate it cleanly in fluid
recursivelyExtractKey ( Traversable $iterator, string $key ) : string Recursively extract the key
render ( string $key, mixed $content = null, boolean $recursive = true, boolean $single = false ) : array

Method Details

extractByKey() public method

Extract by key
public extractByKey ( Traversable $iterator, string $key ) : mixed
$iterator Traversable
$key string
return mixed NULL or whatever we found at $key

flattenArray() public method

Flatten the result structure, to iterate it cleanly in fluid
public flattenArray ( array $content, array $flattened = null ) : array
$content array
$flattened array
return array

recursivelyExtractKey() public method

Recursively extract the key
public recursivelyExtractKey ( Traversable $iterator, string $key ) : string
$iterator Traversable
$key string
return string

render() public method

public render ( string $key, mixed $content = null, boolean $recursive = true, boolean $single = false ) : array
$key string The name of the key from which you wish to extract the value
$content mixed The array or Iterator that contains either the value or arrays of values
$recursive boolean If TRUE, attempts to extract the key from deep nested arrays
$single boolean If TRUE, returns only one value - always the first one - instead of an array of values
return array