2 namespace TYPO3\CMS\Fluid\ViewHelpers;
85 public function render($each, $as, $groupBy, $groupKey =
'groupKey')
91 if (is_object($each)) {
92 if (!$each instanceof \Traversable) {
93 throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception(
'GroupedForViewHelper only supports arrays and objects implementing \Traversable interface', 1253108907);
95 $each = iterator_to_array($each);
100 foreach ($groups[
'values'] as $currentGroupIndex => $group) {
101 $this->templateVariableContainer->add($groupKey, $groups[
'keys'][$currentGroupIndex]);
102 $this->templateVariableContainer->add($as, $group);
104 $this->templateVariableContainer->remove($groupKey);
105 $this->templateVariableContainer->remove($as);
120 $groups = array(
'keys' => array(),
'values' => array());
121 foreach ($elements as $key => $value) {
122 if (is_array($value)) {
123 $currentGroupIndex = isset($value[$groupBy]) ? $value[$groupBy] : null;
124 }
elseif (is_object($value)) {
125 $currentGroupIndex = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($value, $groupBy);
127 throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception(
'GroupedForViewHelper only supports multi-dimensional arrays and objects', 1253120365);
129 $currentGroupKeyValue = $currentGroupIndex;
130 if (is_object($currentGroupIndex)) {
131 if ($currentGroupIndex instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
132 $currentGroupIndex = $currentGroupIndex->_loadRealInstance();
134 $currentGroupIndex = spl_object_hash($currentGroupIndex);
136 $groups[
'keys'][$currentGroupIndex] = $currentGroupKeyValue;
137 $groups[
'values'][$currentGroupIndex][$key] = $value;