1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Sitemap\Controller\Adminhtml\Sitemap;
- use Magento\Framework\App\Action\HttpGetActionInterface;
- /**
- * Controller class Edit. Responsible for rendering of a sitemap edit page
- */
- class Edit extends \Magento\Sitemap\Controller\Adminhtml\Sitemap implements HttpGetActionInterface
- {
- /**
- * Core registry
- *
- * @var \Magento\Framework\Registry
- */
- protected $_coreRegistry = null;
- /**
- * @param \Magento\Backend\App\Action\Context $context
- * @param \Magento\Framework\Registry $coreRegistry
- */
- public function __construct(\Magento\Backend\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry)
- {
- $this->_coreRegistry = $coreRegistry;
- parent::__construct($context);
- }
- /**
- * Edit sitemap
- *
- * @return void
- * @SuppressWarnings(PHPMD.NPathComplexity)
- */
- public function execute()
- {
- // 1. Get ID and create model
- $id = $this->getRequest()->getParam('sitemap_id');
- $model = $this->_objectManager->create(\Magento\Sitemap\Model\Sitemap::class);
- // 2. Initial checking
- if ($id) {
- $model->load($id);
- if (!$model->getId()) {
- $this->messageManager->addErrorMessage(__('This sitemap no longer exists.'));
- $this->_redirect('adminhtml/*/');
- return;
- }
- }
- // 3. Set entered data if was error when we do save
- $data = $this->_objectManager->get(\Magento\Backend\Model\Session::class)->getFormData(true);
- if (!empty($data)) {
- $model->setData($data);
- }
- // 4. Register model to use later in blocks
- $this->_coreRegistry->register('sitemap_sitemap', $model);
- // 5. Build edit form
- $this->_initAction()->_addBreadcrumb(
- $id ? __('Edit Sitemap') : __('New Sitemap'),
- $id ? __('Edit Sitemap') : __('New Sitemap')
- )->_addContent(
- $this->_view->getLayout()->createBlock(\Magento\Sitemap\Block\Adminhtml\Edit::class)
- );
- $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Site Map'));
- $this->_view->getPage()->getConfig()->getTitle()->prepend(
- $model->getId() ? $model->getSitemapFilename() : __('New Site Map')
- );
- $this->_view->renderLayout();
- }
- }
|