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
7 
12 {
16  protected $_pageFactory;
17 
25  public function __construct(
26  \Magento\Backend\Block\Widget\Context $context,
27  \Magento\UrlRewrite\Model\UrlRewriteFactory $rewriteFactory,
28  \Magento\Backend\Helper\Data $adminhtmlData,
29  \Magento\Cms\Model\PageFactory $pageFactory,
30  array $data = []
31  ) {
32  $this->_pageFactory = $pageFactory;
33  parent::__construct($context, $rewriteFactory, $adminhtmlData, $data);
34  }
35 
41  protected function _prepareLayoutFeatures()
42  {
43  if ($this->_getUrlRewrite()->getId()) {
44  $this->_headerText = __('Edit URL Rewrite for CMS page');
45  } else {
46  $this->_headerText = __('Add URL Rewrite for CMS page');
47  }
48 
49  if ($this->_getCmsPage()->getId()) {
50  $this->_addCmsPageLinkBlock();
51  $this->_addEditFormBlock();
52  if ($this->_getUrlRewrite()->getId() === null) {
53  $this->_updateBackButtonLink($this->_adminhtmlData->getUrl('adminhtml/*/edit') . 'cms_page');
54  }
55  } else {
57  $this->_addCmsPageGridBlock();
58  }
59  }
60 
66  private function _getCmsPage()
67  {
68  if (!$this->hasData('cms_page')) {
69  $this->setCmsPage($this->_pageFactory->create());
70  }
71  return $this->getCmsPage();
72  }
73 
79  private function _addCmsPageLinkBlock()
80  {
81  $this->addChild(
82  'cms_page_link',
83  \Magento\UrlRewrite\Block\Link::class,
84  [
85  'item_url' => $this->_adminhtmlData->getUrl('adminhtml/*/*') . 'cms_page',
86  'item_name' => $this->getCmsPage()->getTitle(),
87  'label' => __('CMS page:')
88  ]
89  );
90  }
91 
97  private function _addCmsPageGridBlock()
98  {
99  $this->addChild('cms_pages_grid', \Magento\UrlRewrite\Block\Cms\Page\Grid::class);
100  }
101 
107  protected function _createEditFormBlock()
108  {
109  return $this->getLayout()->createBlock(
110  \Magento\UrlRewrite\Block\Cms\Page\Edit\Form::class,
111  '',
112  ['data' => ['cms_page' => $this->_getCmsPage(), 'url_rewrite' => $this->_getUrlRewrite()]]
113  );
114  }
115 }
__()
Definition: __.php:13
__construct(\Magento\Backend\Block\Widget\Context $context, \Magento\UrlRewrite\Model\UrlRewriteFactory $rewriteFactory, \Magento\Backend\Helper\Data $adminhtmlData, \Magento\Cms\Model\PageFactory $pageFactory, array $data=[])
Definition: Edit.php:25