Edit.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sitemap\Controller\Adminhtml\Sitemap;
  7. use Magento\Framework\App\Action\HttpGetActionInterface;
  8. /**
  9. * Controller class Edit. Responsible for rendering of a sitemap edit page
  10. */
  11. class Edit extends \Magento\Sitemap\Controller\Adminhtml\Sitemap implements HttpGetActionInterface
  12. {
  13. /**
  14. * Core registry
  15. *
  16. * @var \Magento\Framework\Registry
  17. */
  18. protected $_coreRegistry = null;
  19. /**
  20. * @param \Magento\Backend\App\Action\Context $context
  21. * @param \Magento\Framework\Registry $coreRegistry
  22. */
  23. public function __construct(\Magento\Backend\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry)
  24. {
  25. $this->_coreRegistry = $coreRegistry;
  26. parent::__construct($context);
  27. }
  28. /**
  29. * Edit sitemap
  30. *
  31. * @return void
  32. * @SuppressWarnings(PHPMD.NPathComplexity)
  33. */
  34. public function execute()
  35. {
  36. // 1. Get ID and create model
  37. $id = $this->getRequest()->getParam('sitemap_id');
  38. $model = $this->_objectManager->create(\Magento\Sitemap\Model\Sitemap::class);
  39. // 2. Initial checking
  40. if ($id) {
  41. $model->load($id);
  42. if (!$model->getId()) {
  43. $this->messageManager->addErrorMessage(__('This sitemap no longer exists.'));
  44. $this->_redirect('adminhtml/*/');
  45. return;
  46. }
  47. }
  48. // 3. Set entered data if was error when we do save
  49. $data = $this->_objectManager->get(\Magento\Backend\Model\Session::class)->getFormData(true);
  50. if (!empty($data)) {
  51. $model->setData($data);
  52. }
  53. // 4. Register model to use later in blocks
  54. $this->_coreRegistry->register('sitemap_sitemap', $model);
  55. // 5. Build edit form
  56. $this->_initAction()->_addBreadcrumb(
  57. $id ? __('Edit Sitemap') : __('New Sitemap'),
  58. $id ? __('Edit Sitemap') : __('New Sitemap')
  59. )->_addContent(
  60. $this->_view->getLayout()->createBlock(\Magento\Sitemap\Block\Adminhtml\Edit::class)
  61. );
  62. $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Site Map'));
  63. $this->_view->getPage()->getConfig()->getTitle()->prepend(
  64. $model->getId() ? $model->getSitemapFilename() : __('New Site Map')
  65. );
  66. $this->_view->renderLayout();
  67. }
  68. }