From 2da948c15373ec146f273110c61690d1524364d2 Mon Sep 17 00:00:00 2001
From: "michael.danielczok" <michael@pcsg.de>
Date: Fri, 11 Mar 2022 21:45:40 +0100
Subject: [PATCH] feat: Use FAQ schema markup [Accordion].

---
 src/QUI/Bricks/Controls/Accordion.html |  4 ++
 src/QUI/Bricks/Controls/Accordion.php  | 54 ++++++++++++++++++++------
 2 files changed, 47 insertions(+), 11 deletions(-)

diff --git a/src/QUI/Bricks/Controls/Accordion.html b/src/QUI/Bricks/Controls/Accordion.html
index 6810c12..ce86233 100644
--- a/src/QUI/Bricks/Controls/Accordion.html
+++ b/src/QUI/Bricks/Controls/Accordion.html
@@ -37,4 +37,8 @@
             {/if}
         </div>
     {/foreach}
+
+    {if $useFaqStructuredData}
+        {$this->createJSONLDFAQSchemaCode()}
+    {/if}
 </div>
\ No newline at end of file
diff --git a/src/QUI/Bricks/Controls/Accordion.php b/src/QUI/Bricks/Controls/Accordion.php
index 80d8b5b..f9da6b1 100644
--- a/src/QUI/Bricks/Controls/Accordion.php
+++ b/src/QUI/Bricks/Controls/Accordion.php
@@ -15,6 +15,16 @@
  */
 class Accordion extends QUI\Control
 {
+    /**
+     * [
+     *   'entryTitle'   => string,
+     *   'entryContent' => string
+     * ]
+     *
+     * @var array
+     */
+    protected array $entries = [];
+
     /**
      * constructor
      *
@@ -24,13 +34,14 @@ public function __construct($attributes = [])
     {
         // default options
         $this->setAttributes([
-            'nodeName'     => 'section',
-            'class'        => 'quiqqer-accordion',
-            'qui-class'    => 'package/quiqqer/bricks/bin/Controls/Accordion',
-            'stayOpen'     => false, // if true make accordion items stay open when another item is opened
-            'openFirst'    => false, // the first entry is initially opened
-            'listMaxWidth' => 0, // positive numbers only, 0 disabled this option.
-            'entries'      => []
+            'nodeName'             => 'section',
+            'class'                => 'quiqqer-accordion',
+            'qui-class'            => 'package/quiqqer/bricks/bin/Controls/Accordion',
+            'stayOpen'             => false, // if true make accordion items stay open when another item is opened
+            'openFirst'            => false, // the first entry is initially opened
+            'listMaxWidth'         => 0, // positive numbers only, 0 disabled this option.
+            'entries'              => [],
+            'useFaqStructuredData' => false
         ]);
 
         parent::__construct($attributes);
@@ -64,13 +75,34 @@ public function getBody()
             $entries = json_decode($entries, true);
         }
 
+        $this->entries = $entries;
+
         $Engine->assign([
-            'this'         => $this,
-            'openFirst'    => $this->getAttribute('openFirst'),
-            'listMaxWidth' => $maxWidth,
-            'entries'      => $entries
+            'this'                 => $this,
+            'openFirst'            => $this->getAttribute('openFirst'),
+            'listMaxWidth'         => $maxWidth,
+            'entries'              => $this->entries,
+            'useFaqStructuredData' => $this->getAttribute('useFaqStructuredData')
         ]);
 
         return $Engine->fetch(dirname(__FILE__).'/Accordion.html');
     }
+
+    /**
+     * Generate JSON-LD FAQ Schema Code
+     *
+     * @return string
+     * @throws QUI\Exception
+     */
+    public function createJSONLDFAQSchemaCode()
+    {
+        $Engine = QUI::getTemplateManager()->getEngine();
+
+        $Engine->assign([
+            'this'    => $this,
+            'entries' => $this->entries
+        ]);
+
+        return $Engine->fetch(dirname(__FILE__).'/Accordion.JSON-LD-Schema.html');
+    }
 }
-- 
GitLab