(no commit message) master
authorChristian Weiske <cweiske@cweiske.de>
Fri, 26 Sep 2025 14:56:31 +0000 (16:56 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Fri, 26 Sep 2025 14:56:31 +0000 (16:56 +0200)
Page/InheritedPropertyViewHelper.php [new file with mode: 0644]
z-template.html [new file with mode: 0644]

diff --git a/Page/InheritedPropertyViewHelper.php b/Page/InheritedPropertyViewHelper.php
new file mode 100644 (file)
index 0000000..9ebc5af
--- /dev/null
@@ -0,0 +1,69 @@
+<?php\r
+\r
+declare(strict_types=1);\r
+\r
+namespace Vendor\MyExtension\ViewHelpers\Page;\r
+\r
+use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;\r
+use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;\r
+\r
+/**\r
+ * Get a page row property, inherited up through the rootline.\r
+ *\r
+ * When a value is NULL or an empty string "", then the parent page's\r
+ * value is used.\r
+ *\r
+ * The column must be in the rootline already.\r
+ * This can be configured via TYPO3_CONF_VARS[FE][addRootLineFields].\r
+ */\r
+class InheritedPropertyViewHelper extends AbstractViewHelper\r
+{\r
+    protected $escapeOutput = false;\r
+\r
+    public function initializeArguments(): void\r
+    {\r
+        $this->registerArgument(\r
+            'column',\r
+            'string',\r
+            'Page row column name',\r
+            true,\r
+        );\r
+        $this->registerArgument(\r
+            'default',\r
+            'string',\r
+            'Fallback value when all pages have an empty value',\r
+            true,\r
+        );\r
+    }\r
+\r
+    public function render(): mixed\r
+    {\r
+        $column = $this->arguments['column'];\r
+        $rootLine = $this->getRootLine();\r
+\r
+        foreach ($rootLine as $pageRow) {\r
+            if (!array_key_exists($column, $pageRow)) {\r
+                throw new \OutOfRangeException(\r
+                    'Column is not part of the rootline: ' . $column,\r
+                    1758882723\r
+                );\r
+            }\r
+\r
+            if ($pageRow[$column] !== null && $pageRow[$column] !== '') {\r
+                return $pageRow[$column];\r
+            }\r
+        }\r
+\r
+        return $this->arguments['default'];\r
+    }\r
+\r
+    protected function getRootLine(): array\r
+    {\r
+        return $this->getFrontendController()->rootLine;\r
+    }\r
+\r
+    protected function getFrontendController(): TypoScriptFrontendController\r
+    {\r
+        return $GLOBALS['TSFE'];\r
+    }\r
+}\r
diff --git a/z-template.html b/z-template.html
new file mode 100644 (file)
index 0000000..a81b12c
--- /dev/null
@@ -0,0 +1,3 @@
+<f:if condition="{myextension:page.inheritedProperty(column:'tx_mysocial_show_comments',default:1)}">\r
+    <!-- show comments -->\r
+</f:if>\r