From: Christian Weiske Date: Fri, 26 Sep 2025 14:56:31 +0000 (+0200) Subject: (no commit message) X-Git-Url: https://git.cweiske.de/paste/936.git/commitdiff_plain/HEAD?ds=sidebyside --- c2cbb27b97162b8bfdccbfd60884f256d3e32ebd diff --git a/Page/InheritedPropertyViewHelper.php b/Page/InheritedPropertyViewHelper.php new file mode 100644 index 0000000..9ebc5af --- /dev/null +++ b/Page/InheritedPropertyViewHelper.php @@ -0,0 +1,69 @@ +registerArgument( + 'column', + 'string', + 'Page row column name', + true, + ); + $this->registerArgument( + 'default', + 'string', + 'Fallback value when all pages have an empty value', + true, + ); + } + + public function render(): mixed + { + $column = $this->arguments['column']; + $rootLine = $this->getRootLine(); + + foreach ($rootLine as $pageRow) { + if (!array_key_exists($column, $pageRow)) { + throw new \OutOfRangeException( + 'Column is not part of the rootline: ' . $column, + 1758882723 + ); + } + + if ($pageRow[$column] !== null && $pageRow[$column] !== '') { + return $pageRow[$column]; + } + } + + return $this->arguments['default']; + } + + protected function getRootLine(): array + { + return $this->getFrontendController()->rootLine; + } + + protected function getFrontendController(): TypoScriptFrontendController + { + return $GLOBALS['TSFE']; + } +} diff --git a/z-template.html b/z-template.html new file mode 100644 index 0000000..a81b12c --- /dev/null +++ b/z-template.html @@ -0,0 +1,3 @@ + + +