68 lines
2.4 KiB
PHP
68 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace Websmid\CustomHtml\Form\DataProvider;
|
|
|
|
use PrestaShop\PrestaShop\Core\Form\IdentifiableObject\DataProvider\FormDataProviderInterface;
|
|
use Websmid\CustomHtml\Model\CustomHtmlBlock;
|
|
use Websmid\CustomHtml\Model\CustomHtmlFaq;
|
|
use Validate;
|
|
|
|
final class CustomHtmlBlockDataProvider implements FormDataProviderInterface
|
|
{
|
|
public function getData($id)
|
|
{
|
|
$block = new CustomHtmlBlock((int) $id);
|
|
|
|
if (!Validate::isLoadedObject($block)) {
|
|
return $this->getDefaultData();
|
|
}
|
|
|
|
return [
|
|
'id_ws_customhtml_group' => (int) $block->id_ws_customhtml_group,
|
|
'title' => $block->title,
|
|
'type' => $block->type,
|
|
'show_title' => (bool) $block->show_title,
|
|
'custom_class' => $block->custom_class,
|
|
'content' => $block->content,
|
|
'image' => null,
|
|
'description' => $block->description,
|
|
'extra_description' => $block->extra_description,
|
|
'link' => $block->link,
|
|
'alert_type' => $block->alert_type,
|
|
'timeout' => (int) $block->timeout,
|
|
'faqs' => $this->loadFaqs((int) $id),
|
|
'active' => (bool) $block->active,
|
|
];
|
|
}
|
|
|
|
public function getDefaultData()
|
|
{
|
|
return [
|
|
'id_ws_customhtml_group' => 0,
|
|
'title' => '',
|
|
'type' => 'html',
|
|
'show_title' => false,
|
|
'custom_class' => '',
|
|
'content' => '',
|
|
'image' => null,
|
|
'description' => '',
|
|
'extra_description' => '',
|
|
'link' => '',
|
|
'alert_type' => 'info',
|
|
'timeout' => 0,
|
|
'faqs' => [],
|
|
'active' => true,
|
|
];
|
|
}
|
|
|
|
private function loadFaqs(int $idBlock): array
|
|
{
|
|
return array_map(static function (array $faq) {
|
|
return [
|
|
'question' => $faq['question'],
|
|
'answer' => $faq['answer'],
|
|
];
|
|
}, CustomHtmlFaq::getByBlockId($idBlock));
|
|
}
|
|
}
|