54 lines
1.7 KiB
PHP
Executable File
54 lines
1.7 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* @author Olegnax
|
|
* @package Olegnax_GoogleMap
|
|
* @copyright Copyright (c) 2020 Olegnax (http://olegnax.com/). All rights reserved.
|
|
* See COPYING.txt for license details.
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace Olegnax\GoogleMap\Controller\Adminhtml\Location;
|
|
|
|
use Exception;
|
|
use Magento\Backend\Model\View\Result\Redirect;
|
|
use Magento\Framework\Controller\ResultInterface;
|
|
use Olegnax\GoogleMap\Model\Location;
|
|
|
|
class Delete extends \Olegnax\GoogleMap\Controller\Adminhtml\Location
|
|
{
|
|
|
|
/**
|
|
* Delete action
|
|
*
|
|
* @return ResultInterface
|
|
*/
|
|
public function execute()
|
|
{
|
|
/** @var Redirect $resultRedirect */
|
|
$resultRedirect = $this->resultRedirectFactory->create();
|
|
// check if we know what should be deleted
|
|
$id = $this->getRequest()->getParam('location_id');
|
|
if ($id) {
|
|
try {
|
|
// init model and delete
|
|
$model = $this->_objectManager->create(Location::class);
|
|
$model->load($id);
|
|
$model->delete();
|
|
// display success message
|
|
$this->messageManager->addSuccessMessage(__('You deleted the Location.'));
|
|
// go to grid
|
|
return $resultRedirect->setPath('*/*/');
|
|
} catch (Exception $e) {
|
|
// display error message
|
|
$this->messageManager->addErrorMessage($e->getMessage());
|
|
// go back to edit form
|
|
return $resultRedirect->setPath('*/*/edit', ['location_id' => $id]);
|
|
}
|
|
}
|
|
// display error message
|
|
$this->messageManager->addErrorMessage(__('We can\'t find a Location to delete.'));
|
|
// go to grid
|
|
return $resultRedirect->setPath('*/*/');
|
|
}
|
|
}
|