„src/git@dev.quiqqer.com:quiqqer/timeline.git“ existiert nicht auf „ce120e677eb8d5ae51556eef6b1e76de22bd34c0“
Newer
Older
<?php
namespace QUI\Bricks\Controls;
use QUI;

Patrick Müller
committed
use Seld\JsonLint\JsonParser;
/**
* Class Accordion
*
* @package quiqqer/bricks
*/
class Accordion extends QUI\Control
{
/**
* [
* 'entryTitle' => string,
* 'entryContent' => string
* ]
*
* @var array
*/
protected array $entries = [];
/**
* constructor
*
* @param array $attributes
*/
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' => [],
'useFaqStructuredData' => false
]);
parent::__construct($attributes);
$this->addCSSFile(
);
}
/**
* (non-PHPdoc)
*
* @see \QUI\Control::create()
*/
public function getBody(): string
$Engine = QUI::getTemplateManager()->getEngine();
$entries = $this->getAttribute('entries');
if ($this->getAttribute('stayOpen') !== false) {
$this->setJavaScriptControlOption('stayopen', $this->getAttribute('stayOpen'));
}
$maxWidth = false;
if (intval($this->getAttribute('listMaxWidth')) > 0) {
$maxWidth = intval($this->getAttribute('listMaxWidth'));
}
if (is_string($entries)) {

Patrick Müller
committed
$entries = \str_replace("\n", "", $entries);
try {
$entries = (new JsonParser())->parse($entries, JsonParser::PARSE_TO_ASSOC);

Patrick Müller
committed
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
$entries = [];
}
}
if (!\is_array($entries)) {
$entries = [];
$this->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(): string
{
$Engine = QUI::getTemplateManager()->getEngine();
if (empty($this->entries)) {
$this->entries = $this->getAttribute('entries');
}
if (empty($this->entries)) {
return '';
}
'entries' => $this->entries
]);
return $Engine->fetch(dirname(__FILE__) . '/Accordion.JSON-LD-Schema.html');