85 public function render($each, $as, $groupBy, $groupKey =
'groupKey') {
90 if (is_object($each)) {
91 if (!$each instanceof \Traversable) {
92 throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception(
'GroupedForViewHelper only supports arrays and objects implementing \Traversable interface', 1253108907);
94 $each = iterator_to_array($each);
99 foreach ($groups[
'values'] as $currentGroupIndex => $group) {
100 $this->templateVariableContainer->add($groupKey, $groups[
'keys'][$currentGroupIndex]);
101 $this->templateVariableContainer->add($as, $group);
103 $this->templateVariableContainer->remove($groupKey);
104 $this->templateVariableContainer->remove($as);
118 $groups = array(
'keys' => array(),
'values' => array());
119 foreach ($elements as $key => $value) {
120 if (is_array($value)) {
121 $currentGroupIndex = isset($value[$groupBy]) ? $value[$groupBy] : NULL;
122 } elseif (is_object($value)) {
125 throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception(
'GroupedForViewHelper only supports multi-dimensional arrays and objects', 1253120365);
127 $currentGroupKeyValue = $currentGroupIndex;
128 if (is_object($currentGroupIndex)) {
129 if ($currentGroupIndex instanceof \
TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
130 $currentGroupIndex = $currentGroupIndex->_loadRealInstance();
132 $currentGroupIndex = spl_object_hash($currentGroupIndex);
134 $groups[
'keys'][$currentGroupIndex] = $currentGroupKeyValue;
135 $groups[
'values'][$currentGroupIndex][$key] = $value;
static getPropertyPath($subject, $propertyPath)
render($each, $as, $groupBy, $groupKey='groupKey')
groupElements(array $elements, $groupBy)