From b1b8d7e49188c8b46fbf190fce9ffe80796233b2 Mon Sep 17 00:00:00 2001 From: "michael.danielczok" <michael@pcsg.de> Date: Tue, 30 Nov 2021 16:32:44 +0100 Subject: [PATCH] feat: Site category has new setting: template (default and accordeon menu). --- locale.xml | 22 +++++- site.xml | 20 +++++ src/QUI/FAQ/Controls/Accordion.php | 2 +- types/category.html | 120 +++++++++++++++-------------- types/category.php | 36 +++++++-- 5 files changed, 133 insertions(+), 67 deletions(-) diff --git a/locale.xml b/locale.xml index a55087e..f85546e 100644 --- a/locale.xml +++ b/locale.xml @@ -69,8 +69,24 @@ <en><![CDATA[Offset]]></en> </locale> <locale name="quiqqer.faq.category.settings.offset.desc"> - <de><![CDATA[Der Versatz (in Pixel) sagt, um wie viele zusätzliche Pixel soll die Seite gescrollt werden, wenn man ein FAQ Titel anklickt. Das ist vor allem dann hilfreich, wenn das Menü den Inhalt verdecken würde.]]></de> - <en><![CDATA[The offset (in pixels) specifies how many additional pixels the page should scroll when you click on a FAQ title. By doing this the menu no longer hides the linked content.]]></en> + <de><![CDATA[Der Versatz (in Pixel) sagt, um wie viele zusätzliche Pixel soll die Seite gescrollt werden, wenn man ein FAQ Titel anklickt. Das ist vor allem dann hilfreich, wenn das Menü den Inhalt verdecken würde. Es funktioniert nur im Standard-Template.]]></de> + <en><![CDATA[The offset (in pixels) specifies how many additional pixels the page should scroll when you click on a FAQ title. By doing this the menu no longer hides the linked content. It takes affect in default template.]]></en> + </locale> + <locale name="quiqqer.faq.category.settings.template"> + <de><![CDATA[Template]]></de> + <en><![CDATA[Template]]></en> + </locale> + <locale name="quiqqer.faq.category.settings.template.default"> + <de><![CDATA[Standard]]></de> + <en><![CDATA[Default]]></en> + </locale> + <locale name="quiqqer.faq.category.settings.template.accordion"> + <de><![CDATA[FAQ Akkordeon Menü]]></de> + <en><![CDATA[FAQ Accordion Menu]]></en> + </locale> + <locale name="quiqqer.faq.settings.accordion.stayOpen"> + <de><![CDATA[FAQ Akkordeon Menü: Einträge bleiben auf]]></de> + <en><![CDATA[FAQ Accordion Menu: Entries stay open]]></en> </locale> <!-- Brick: FAQ Accordion Menu --> @@ -127,7 +143,7 @@ <en><![CDATA[Show "more entries" button]]></en> </locale> <locale name="brick.accordion.settings.showMoreButton.desc" html="true"> - <de><![CDATA[Der Button wird nicht angezeigt, wenn es nicht mehr Einträgen gibt, als der Baustein anzeigt. Wenn der Baustein 10 Einträge listet aber es nur 5 FAQ Einträgen gibt, wird kein Button angezeigt. Bitte die Einstellungn <strong>"Maximale Anzahl der Einträge"</strong> beachten.]]></de> + <de><![CDATA[Der Button wird nicht angezeigt, wenn es nicht mehr Einträge gibt, als der Baustein anzeigt. Wenn der Baustein 10 Einträge listet aber es nur 5 FAQ Einträgen gibt, wird kein Button angezeigt. Bitte die Einstellungn <strong>"Maximale Anzahl der Einträge"</strong> beachten.]]></de> <en><![CDATA[The button is not displayed if there are not more entries than the brick displays. If the brick lists 10 entries and there are only 5 faq entries, no button will be displayed. Please note the <strong>"Maximum number of entries"</strong> setting.]]></en> </locale> <locale name="brick.accordion.button.more"> diff --git a/site.xml b/site.xml index 303de97..c878918 100644 --- a/site.xml +++ b/site.xml @@ -16,6 +16,8 @@ </desc> <attributes> + <attribute default="default">quiqqer.faq.settings.template</attribute> + <attribute default="1">quiqqer.faq.settings.accordion.stayOpen</attribute> <attribute default="0">quiqqer.faq.settings.offset</attribute> </attributes> @@ -26,6 +28,24 @@ <locale group="quiqqer/faq" var="quiqqer.faq.category.settings.title"/> </title> + <select conf="quiqqer.faq.settings.template"> + <text> + <locale group="quiqqer/faq" var="quiqqer.faq.category.settings.template"/> + </text> + <option value="default"> + <locale group="quiqqer/faq" var="quiqqer.faq.category.settings.template.default"/> + </option> + <option value="accordion"> + <locale group="quiqqer/faq" var="quiqqer.faq.category.settings.template.accordion"/> + </option> + </select> + + <input conf="quiqqer.faq.settings.accordion.stayOpen" type="checkbox"> + <text> + <locale group="quiqqer/faq" var="quiqqer.faq.settings.accordion.stayOpen"/> + </text> + </input> + <input conf="quiqqer.faq.settings.offset" type="number"> <text> <locale group="quiqqer/faq" var="quiqqer.faq.category.settings.offset"/> diff --git a/src/QUI/FAQ/Controls/Accordion.php b/src/QUI/FAQ/Controls/Accordion.php index ccbd644..ab02df5 100644 --- a/src/QUI/FAQ/Controls/Accordion.php +++ b/src/QUI/FAQ/Controls/Accordion.php @@ -122,7 +122,7 @@ class Accordion extends QUI\Control } $Accordion = new QUI\Bricks\Controls\Accordion([ - 'stayOpen' => $this->getAttribute('stayOpen'), + 'stayOpen' => \boolval($this->getAttribute('stayOpen')), 'openFirst' => $this->getAttribute('openFirst'), 'listMaxWidth' => $this->getAttribute('listMaxWidth'), 'entries' => $entries diff --git a/types/category.html b/types/category.html index b7ca138..d99c49a 100644 --- a/types/category.html +++ b/types/category.html @@ -1,69 +1,77 @@ {if $Template->getAttribute('content-body') && $Site->getAttribute('content')} -<section class="content-body"> - {$Site->getAttribute('content')} -</section> + <section class="content-body"> + {$Site->getAttribute('content')} + </section> {/if} -{if $offset} -<!-- -This CSS is used to scroll the page down a bit when accessed with a # in the url. -By doing this the menu no longer hides the linked content. ---> -<style type="text/css"> - :target::before { - content: ''; - display: block; - height: 80px; - margin-top: -80px; - } -</style> -{/if} - -<section itemscope itemtype="http://schema.org/ItemList" - class="content-template quiqqer-faq clear-fix" - data-qui="package/quiqqer/faq/bin/Category" - data-qui-options-offset="{$offset}" -> - {if count($entries)} - <ul class="quiqqer-faq-list" id="faqList" name="faqList"> - {foreach $entries as $Faq} - <li> - <a href="{url site=$Site}#faq{$Faq->getId()}"> - {$Faq->getAttribute('title')} - </a> - </li> - {/foreach} - </ul> +{* Template: default*} +{if $faqTemplate == 'default'} + {if $offset} + {* + This CSS is used to scroll the page down a bit when accessed with a # in the url. + By doing this the menu no longer hides the linked content. + *} + <style type="text/css"> + :target::before { + content: ''; + display: block; + height: {$offset}px; + margin-top: -{$offset}px; + } + </style> {/if} - <hr /> + <section itemscope itemtype="http://schema.org/ItemList" + class="content-template quiqqer-faq clear-fix" + data-qui="package/quiqqer/faq/bin/Category" + data-qui-options-offset="{$offset}" + > + {if count($entries)} + <ul class="quiqqer-faq-list" id="faqList" name="faqList"> + {foreach $entries as $Faq} + <li> + <a href="{url site=$Site}#faq{$Faq->getId()}"> + {$Faq->getAttribute('title')} + </a> + </li> + {/foreach} + </ul> + {/if} - {foreach $entries as $Faq} - <article id="faq{$Faq->getId()}" class="clear-fix"> - <header> - <h2>{$Faq->getAttribute('title')}</h2> - </header> + <hr /> - {if $Faq->getAttribute('short')} - <div class="content-short"> - {$Faq->getAttribute('short')|nl2br} - </div> - {/if} + {foreach $entries as $Faq} + <article id="faq{$Faq->getId()}" class="clear-fix"> + <header> + <h2>{$Faq->getAttribute('title')}</h2> + </header> - <div class="content-body"> - {$Faq->getAttribute('content')} - </div> + {if $Faq->getAttribute('short')} + <div class="content-short"> + {$Faq->getAttribute('short')|nl2br} + </div> + {/if} - <a href="#faqList" class="quiqqer-faq-list-linkToTop"> - {locale group="quiqqer/faq" value="link.to.top"} <span class="fa fa-fw fa-level-up"></span> - </a> + <div class="content-body"> + {$Faq->getAttribute('content')} + </div> - </article> + <a href="#faqList" class="quiqqer-faq-list-linkToTop"> + {locale group="quiqqer/faq" value="link.to.top"} <span class="fa fa-fw fa-level-up"></span> + </a> - {if !($Faq@last)} - <hr /> - {/if} + </article> - {/foreach} + {if !($Faq@last)} + <hr /> + {/if} + {/foreach} + </section> +{/if} -</section> +{* Template: accordion*} +{if $faqTemplate == 'accordion'} + <section class="content-template quiqqer-faq"> + {$FAQControl->create()} + </section> +{/if} \ No newline at end of file diff --git a/types/category.php b/types/category.php index f2a1785..a7b1ac5 100644 --- a/types/category.php +++ b/types/category.php @@ -1,12 +1,34 @@ <?php -$entries = $Site->getChildren(array( +$entries = $Site->getChildren([ 'type' => 'quiqqer/faq:types/entry' -)); +]); -$offset = intval($Site->getAttribute('quiqqer.faq.settings.offset')); +$faqTemplate = 'default'; +$offset = false; +$FAQControl = null; -$Engine->assign(array( - 'entries' => $entries, - 'offset' => $offset -)); +switch ($Site->getAttribute('quiqqer.faq.settings.template')) { + case 'accordion': + $faqTemplate = 'accordion'; + + $FAQControl = new \QUI\FAQ\Controls\Accordion([ + 'max' => 50, + 'stayOpen' => $Site->getAttribute('quiqqer.faq.settings.accordion.stayOpen'), + 'parentSite' => $Site + ]); + + break; + case 'default': + default: + $offset = intval($Site->getAttribute('quiqqer.faq.settings.offset')); + $faqTemplate = 'default'; + break; +} + +$Engine->assign([ + 'entries' => $entries, + 'faqTemplate' => $faqTemplate, + 'offset' => $offset, + 'FAQControl' => $FAQControl +]); -- GitLab