68 lines
1.9 KiB
PHP
68 lines
1.9 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\ImageManager\Block\Adminhtml\Image;
|
|
|
|
use Esun\ImageManager\Model\Image;
|
|
use Esun\ImageManager\Model\ImageFactory;
|
|
use Esun\ImageManager\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
|
|
use Magento\Backend\Block\Template;
|
|
use Magento\Backend\Block\Template\Context;
|
|
use Magento\Framework\UrlInterface;
|
|
use Magento\Store\Model\StoreManagerInterface;
|
|
|
|
class EditBlock extends Template
|
|
{
|
|
private ?Image $image = null;
|
|
|
|
public function __construct(
|
|
Context $context,
|
|
private readonly ImageFactory $imageFactory,
|
|
private readonly CategoryCollectionFactory $categoryCollectionFactory,
|
|
private readonly StoreManagerInterface $storeManager,
|
|
array $data = []
|
|
) {
|
|
parent::__construct($context, $data);
|
|
}
|
|
|
|
public function getImageModel(): Image
|
|
{
|
|
if ($this->image === null) {
|
|
$this->image = $this->imageFactory->create();
|
|
$id = (int) $this->getRequest()->getParam('id');
|
|
if ($id > 0) {
|
|
$this->image->load($id);
|
|
}
|
|
}
|
|
return $this->image;
|
|
}
|
|
|
|
public function getCategories()
|
|
{
|
|
return $this->categoryCollectionFactory->create()
|
|
->addFieldToFilter('status', 1)
|
|
->setOrder('sort_order', 'ASC')
|
|
->setOrder('name', 'ASC');
|
|
}
|
|
|
|
public function getMediaUrl(string $path): string
|
|
{
|
|
return $this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA) . ltrim($path, '/');
|
|
}
|
|
|
|
public function getSaveUrl(): string
|
|
{
|
|
return $this->getUrl('esun_image_manager/image/save');
|
|
}
|
|
|
|
public function getBackUrl(): string
|
|
{
|
|
return $this->getUrl('esun_image_manager/image/index');
|
|
}
|
|
|
|
public function getCategoryUrl(): string
|
|
{
|
|
return $this->getUrl('esun_image_manager/category/new');
|
|
}
|
|
}
|