63 lines
2.2 KiB
PHP
Executable File
63 lines
2.2 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Copyright © All rights reserved.
|
|
* See COPYING.txt for license details.
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace JR\NetSuite\Controller\Adminhtml\Location;
|
|
|
|
class Edit extends \JR\NetSuite\Controller\Adminhtml\Location
|
|
{
|
|
|
|
protected $resultPageFactory;
|
|
|
|
/**
|
|
* @param \Magento\Backend\App\Action\Context $context
|
|
* @param \Magento\Framework\Registry $coreRegistry
|
|
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
|
|
*/
|
|
public function __construct(
|
|
\Magento\Backend\App\Action\Context $context,
|
|
\Magento\Framework\Registry $coreRegistry,
|
|
\Magento\Framework\View\Result\PageFactory $resultPageFactory
|
|
) {
|
|
$this->resultPageFactory = $resultPageFactory;
|
|
parent::__construct($context, $coreRegistry);
|
|
}
|
|
|
|
/**
|
|
* Edit action
|
|
*
|
|
* @return \Magento\Framework\Controller\ResultInterface
|
|
*/
|
|
public function execute()
|
|
{
|
|
// 1. Get ID and create model
|
|
$id = $this->getRequest()->getParam('location_id');
|
|
$model = $this->_objectManager->create(\JR\NetSuite\Model\Location::class);
|
|
|
|
// 2. Initial checking
|
|
if ($id) {
|
|
$model->load($id);
|
|
if (!$model->getId()) {
|
|
$this->messageManager->addErrorMessage(__('This Location no longer exists.'));
|
|
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
|
|
$resultRedirect = $this->resultRedirectFactory->create();
|
|
return $resultRedirect->setPath('*/*/');
|
|
}
|
|
}
|
|
$this->_coreRegistry->register('jr_netsuite_location', $model);
|
|
|
|
// 3. Build edit form
|
|
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
|
|
$resultPage = $this->resultPageFactory->create();
|
|
$this->initPage($resultPage)->addBreadcrumb(
|
|
$id ? __('Edit Location') : __('New Location'),
|
|
$id ? __('Edit Location') : __('New Location')
|
|
);
|
|
$resultPage->getConfig()->getTitle()->prepend(__('Locations'));
|
|
$resultPage->getConfig()->getTitle()->prepend($model->getId() ? __('Edit Location %1', $model->getId()) : __('New Location'));
|
|
return $resultPage;
|
|
}
|
|
} |