|
1
|
|
|
<?php |
|
2
|
|
|
namespace Qbus\Qbtools\ViewHelpers; |
|
3
|
|
|
|
|
4
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
5
|
|
|
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; |
|
6
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager; |
|
7
|
|
|
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; |
|
8
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; |
|
9
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; |
|
10
|
|
|
|
|
11
|
|
|
class RenderContentViewHelper extends AbstractViewHelper |
|
12
|
|
|
{ |
|
13
|
|
|
use CompileWithRenderStatic; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var bool |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $escapeOutput = false; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Initialize arguments |
|
22
|
|
|
*/ |
|
23
|
|
|
public function initializeArguments() |
|
24
|
|
|
{ |
|
25
|
|
|
$this->registerArgument('uid', 'int', '', false, 0); |
|
26
|
|
|
$this->registerArgument('pid', 'int', '', false, 0); |
|
27
|
|
|
$this->registerArgument('colpos', 'int', '', false, 0); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param array $arguments |
|
32
|
|
|
* @param \Closure $renderChildrenClosure |
|
33
|
|
|
* @param RenderingContextInterface $renderingContext |
|
34
|
|
|
* @return string |
|
35
|
|
|
*/ |
|
36
|
|
|
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string |
|
37
|
|
|
{ |
|
38
|
|
|
$uid = $arguments['uid']; |
|
39
|
|
|
$pid = $arguments['pid']; |
|
40
|
|
|
$colpos = $arguments['colpos']; |
|
41
|
|
|
|
|
42
|
|
|
$objectManager = GeneralUtility::makeInstance(ObjectManager::class); |
|
43
|
|
|
$configurationManager = $objectManager->get(ConfigurationManagerInterface::class); |
|
44
|
|
|
$cObj = $configurationManager->getContentObject(); |
|
45
|
|
|
|
|
46
|
|
|
$content = ''; |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
if ($uid > 0) { |
|
50
|
|
|
$conf = array( |
|
51
|
|
|
'tables' => 'tt_content', |
|
52
|
|
|
'source' => $uid, |
|
53
|
|
|
'dontCheckPid' => 1 |
|
54
|
|
|
); |
|
55
|
|
|
|
|
56
|
|
|
$GLOBALS['TSFE']->addCacheTags(['tt_content_' . $uid]); |
|
57
|
|
|
$content = $cObj->cObjGetSingle('RECORDS', $conf); |
|
58
|
|
|
} elseif ($pid > 0) { |
|
59
|
|
|
$conf = array( |
|
60
|
|
|
'table' => 'tt_content', |
|
61
|
|
|
'select.' => array( |
|
62
|
|
|
'orderBy' => 'sorting', |
|
63
|
|
|
'pidInList' => (string) $pid, |
|
64
|
|
|
'where' => 'colPos=' . intval($colpos), |
|
65
|
|
|
'languageField' => 'sys_language_uid', |
|
66
|
|
|
), |
|
67
|
|
|
); |
|
68
|
|
|
|
|
69
|
|
|
// This requires EXT:autoflush to work |
|
70
|
|
|
$tags = array(); |
|
71
|
|
|
foreach (explode(',', $pid) as $p) { |
|
72
|
|
|
$tags[] = 'tt_content_pid_' . $p; |
|
73
|
|
|
$tags[] = 'pages_' . $p; |
|
74
|
|
|
} |
|
75
|
|
|
$GLOBALS['TSFE']->addCacheTags($tags); |
|
76
|
|
|
$content = $cObj->cObjGetSingle('CONTENT', $conf); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return $content; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|