diff --git a/src/QUI/Bricks/Controls/Accordion.html b/src/QUI/Bricks/Controls/Accordion.html index 6810c12e4c7edeb3a692790a3021d9ba2d1c4ce9..ce862339c637dcf47d6cb5224e41a2d2224c213d 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 80d8b5bf0d9bd707abd6cc76ca905e437cc810bf..f9da6b1336b1d63afc887836ddadd65c946f2ee7 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'); + } }