Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Edit.php
Go to the documentation of this file.
1 <?php
8 
10 {
16  protected $_coreRegistry = null;
17 
22  public function __construct(\Magento\Backend\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry)
23  {
24  $this->_coreRegistry = $coreRegistry;
25  parent::__construct($context);
26  }
27 
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 
40  // 2. Initial checking
41  if ($id) {
42  $model->load($id);
43  if (!$model->getId()) {
44  $this->messageManager->addErrorMessage(__('This sitemap no longer exists.'));
45  $this->_redirect('adminhtml/*/');
46  return;
47  }
48  }
49 
50  // 3. Set entered data if was error when we do save
51  $data = $this->_objectManager->get(\Magento\Backend\Model\Session::class)->getFormData(true);
52  if (!empty($data)) {
53  $model->setData($data);
54  }
55 
56  // 4. Register model to use later in blocks
57  $this->_coreRegistry->register('sitemap_sitemap', $model);
58 
59  // 5. Build edit form
60  $this->_initAction()->_addBreadcrumb(
61  $id ? __('Edit Sitemap') : __('New Sitemap'),
62  $id ? __('Edit Sitemap') : __('New Sitemap')
63  )->_addContent(
64  $this->_view->getLayout()->createBlock(\Magento\Sitemap\Block\Adminhtml\Edit::class)
65  );
66  $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Site Map'));
67  $this->_view->getPage()->getConfig()->getTitle()->prepend(
68  $model->getId() ? $model->getSitemapFilename() : __('New Site Map')
69  );
70  $this->_view->renderLayout();
71  }
72 }
$id
Definition: fieldset.phtml:14
__construct(\Magento\Backend\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry)
Definition: Edit.php:22
__()
Definition: __.php:13