init
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\Wiki\Block\Adminhtml\Homepage;
|
||||
|
||||
use Esun\Wiki\Model\Homepage;
|
||||
use Esun\Wiki\Model\HomepageFactory;
|
||||
use Esun\Wiki\Model\ResourceModel\Homepage\CollectionFactory;
|
||||
use Magento\Backend\Block\Template;
|
||||
use Magento\Backend\Block\Template\Context;
|
||||
use Magento\Cms\Model\Wysiwyg\Config as WysiwygConfig;
|
||||
use Magento\Framework\Data\FormFactory;
|
||||
use Magento\Framework\UrlInterface;
|
||||
|
||||
class EditBlock extends Template
|
||||
{
|
||||
private ?Homepage $homepage = null;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
private readonly HomepageFactory $homepageFactory,
|
||||
private readonly CollectionFactory $collectionFactory,
|
||||
private readonly FormFactory $formFactory,
|
||||
private readonly WysiwygConfig $wysiwygConfig,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $data);
|
||||
}
|
||||
|
||||
public function getHomepage(): Homepage
|
||||
{
|
||||
if ($this->homepage === null) {
|
||||
$homepage = $this->collectionFactory->create()
|
||||
->setPageSize(1)
|
||||
->getFirstItem();
|
||||
$this->homepage = $homepage->getId() ? $homepage : $this->homepageFactory->create();
|
||||
|
||||
if (!$this->homepage->getData('title')) {
|
||||
$this->homepage->setData('title', 'eSUN Wiki');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->homepage;
|
||||
}
|
||||
|
||||
public function getSaveUrl(): string
|
||||
{
|
||||
return $this->getUrl('esun_wiki/homepage/save');
|
||||
}
|
||||
|
||||
public function getCategoriesUrl(): string
|
||||
{
|
||||
return $this->getUrl('esun_wiki/category/index');
|
||||
}
|
||||
|
||||
public function getPreviewUrl(): string
|
||||
{
|
||||
return rtrim($this->_storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_LINK), '/') . '/wiki';
|
||||
}
|
||||
|
||||
public function getContentEditorHtml(): string
|
||||
{
|
||||
$form = $this->formFactory->create();
|
||||
$editor = $form->addField('content', 'editor', [
|
||||
'name' => 'content',
|
||||
'label' => __('Homepage Content'),
|
||||
'title' => __('Homepage Content'),
|
||||
'style' => 'height:36em',
|
||||
'required' => false,
|
||||
'value' => (string) $this->getHomepage()->getData('content'),
|
||||
'config' => $this->wysiwygConfig->getConfig([
|
||||
'add_variables' => false,
|
||||
'add_widgets' => true,
|
||||
'add_images' => true,
|
||||
'is_pagebuilder_enabled' => true,
|
||||
'pagebuilder_button' => true,
|
||||
]),
|
||||
]);
|
||||
|
||||
return $editor->getElementHtml();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user