-
-
Notifications
You must be signed in to change notification settings - Fork 55
/
ContentUtility.php
55 lines (49 loc) · 1.45 KB
/
ContentUtility.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
declare(strict_types = 1);
namespace FriendsOfTYPO3\Headless\Utility;
/***
*
* This file is part of the "headless" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*
* (c) 2019
*
***/
/**
* ContentUtility
*
* This class group elements by column position, for easier frontend rendering.
*/
class ContentUtility
{
/**
* This method takes whole content as JSON string, breaks it per element, and pass to groupContentElementByColPos method to group content by colPos.
*
* @param $content
* @param array $configuration
* @return string|null
*/
public function groupContent($content, array $configuration): string
{
$contents = $this->cObj->cObjGetSingle($configuration['10'], $configuration['10.']);
$contentData = array_map('trim', (array_slice(explode('###BREAK###', $contents), 0, -1)));
return json_encode($this->groupContentElementsByColPos($contentData));
}
/**
* Groups content by colPos.
*
* @param array $contentElements
* @return array
*/
protected function groupContentElementsByColPos(array $contentElements): array
{
$data = [];
foreach ($contentElements as $key => $element) {
$element = json_decode($element);
$data['colPos' . $element->colPos][] = $element;
}
return $data;
}
}