This commit is contained in:
2026-09-15 10:35:56 +08:00
commit 782f8ea7aa
4086 changed files with 631288 additions and 0 deletions
@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
namespace Esun\ImageManager\Block\Adminhtml\Category;
use Esun\ImageManager\Model\Category;
use Esun\ImageManager\Model\CategoryFactory;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
class EditBlock extends Template
{
private ?Category $category = null;
public function __construct(
Context $context,
private readonly CategoryFactory $categoryFactory,
array $data = []
) {
parent::__construct($context, $data);
}
public function getCategory(): Category
{
if ($this->category === null) {
$this->category = $this->categoryFactory->create();
$id = (int) $this->getRequest()->getParam('id');
if ($id > 0) {
$this->category->load($id);
}
}
return $this->category;
}
public function getSaveUrl(): string
{
return $this->getUrl('esun_image_manager/category/save');
}
public function getBackUrl(): string
{
return $this->getUrl('esun_image_manager/category/index');
}
}
@@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
namespace Esun\ImageManager\Block\Adminhtml\Category;
use Esun\ImageManager\Model\ResourceModel\Category\Collection;
use Esun\ImageManager\Model\ResourceModel\Category\CollectionFactory;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
class ListBlock extends Template
{
private ?Collection $categories = null;
public function __construct(
Context $context,
private readonly CollectionFactory $collectionFactory,
array $data = []
) {
parent::__construct($context, $data);
}
public function getCategories(): Collection
{
if ($this->categories === null) {
$this->categories = $this->collectionFactory->create()
->setOrder('sort_order', 'ASC')
->setOrder('category_id', 'DESC');
$query = trim((string) $this->getRequest()->getParam('query'));
if ($query !== '') {
$this->categories->addFieldToFilter(
['name', 'identifier'],
[['like' => '%' . $query . '%'], ['like' => '%' . $query . '%']]
);
}
}
return $this->categories;
}
public function getQueryFilter(): string
{
return trim((string) $this->getRequest()->getParam('query'));
}
public function getNewUrl(): string
{
return $this->getUrl('esun_image_manager/category/new');
}
public function getIndexUrl(): string
{
return $this->getUrl('esun_image_manager/category/index');
}
public function getEditUrl(int $id): string
{
return $this->getUrl('esun_image_manager/category/edit', ['id' => $id]);
}
public function getDeleteUrl(int $id): string
{
return $this->getUrl('esun_image_manager/category/delete', ['id' => $id]);
}
}
@@ -0,0 +1,67 @@
<?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');
}
}