36 lines
1.0 KiB
PHP
36 lines
1.0 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\ImageManager\Controller\Adminhtml\Image;
|
|
|
|
use Esun\ImageManager\Model\ImageFactory;
|
|
use Magento\Backend\App\Action;
|
|
use Magento\Framework\View\Result\PageFactory;
|
|
|
|
class Edit extends Action
|
|
{
|
|
public const ADMIN_RESOURCE = 'Esun_ImageManager::images_save';
|
|
|
|
public function __construct(
|
|
Action\Context $context,
|
|
private readonly PageFactory $pageFactory,
|
|
private readonly ImageFactory $imageFactory
|
|
) {
|
|
parent::__construct($context);
|
|
}
|
|
|
|
public function execute()
|
|
{
|
|
$id = (int) $this->getRequest()->getParam('id');
|
|
if ($id > 0 && !$this->imageFactory->create()->load($id)->getId()) {
|
|
$this->messageManager->addErrorMessage(__('The image no longer exists.'));
|
|
return $this->resultRedirectFactory->create()->setPath('esun_image_manager/image/index');
|
|
}
|
|
|
|
$page = $this->pageFactory->create();
|
|
$page->getConfig()->getTitle()->prepend($id ? __('Edit Image') : __('New Image'));
|
|
|
|
return $page;
|
|
}
|
|
}
|