3 declare(strict_types=1);
\r
5 namespace Vendor\MyExtension\ViewHelpers\Page;
\r
7 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
\r
8 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
\r
11 * Get a page row property, inherited up through the rootline.
\r
13 * When a value is NULL or an empty string "", then the parent page's
\r
16 * The column must be in the rootline already.
\r
17 * This can be configured via TYPO3_CONF_VARS[FE][addRootLineFields].
\r
19 class InheritedPropertyViewHelper extends AbstractViewHelper
\r
21 protected $escapeOutput = false;
\r
23 public function initializeArguments(): void
\r
25 $this->registerArgument(
\r
28 'Page row column name',
\r
31 $this->registerArgument(
\r
34 'Fallback value when all pages have an empty value',
\r
39 public function render(): mixed
\r
41 $column = $this->arguments['column'];
\r
42 $rootLine = $this->getRootLine();
\r
44 foreach ($rootLine as $pageRow) {
\r
45 if (!array_key_exists($column, $pageRow)) {
\r
46 throw new \OutOfRangeException(
\r
47 'Column is not part of the rootline: ' . $column,
\r
52 if ($pageRow[$column] !== null && $pageRow[$column] !== '') {
\r
53 return $pageRow[$column];
\r
57 return $this->arguments['default'];
\r
60 protected function getRootLine(): array
\r
62 return $this->getFrontendController()->rootLine;
\r
65 protected function getFrontendController(): TypoScriptFrontendController
\r
67 return $GLOBALS['TSFE'];
\r