_pageFactory = $pageFactory; parent::__construct( $context, $registry, $formFactory, $optionProvider, $rewriteFactory, $systemStore, $adminhtmlData, $data ); $this->cmsPageUrlPathGenerator = $cmsPageUrlPathGenerator; } /** * Form post init * * @param \Magento\Framework\Data\Form $form * @return \Magento\UrlRewrite\Block\Cms\Page\Edit\Form */ protected function _formPostInit($form) { $cmsPage = $this->_getCmsPage(); $form->setAction( $this->_adminhtmlData->getUrl( 'adminhtml/*/save', ['id' => $this->_getModel()->getId(), 'cms_page' => $cmsPage->getId()] ) ); // Fill request path and target path elements /** @var $requestPath \Magento\Framework\Data\Form\Element\AbstractElement */ $requestPath = $this->getForm()->getElement('request_path'); /** @var $targetPath \Magento\Framework\Data\Form\Element\AbstractElement */ $targetPath = $this->getForm()->getElement('target_path'); $model = $this->_getModel(); if (!$model->getId()) { $sessionData = $this->_getSessionData(); if (!isset($sessionData['request_path'])) { $requestPath->setValue($this->cmsPageUrlPathGenerator->getUrlPath($cmsPage)); } $targetPath->setValue($this->cmsPageUrlPathGenerator->getCanonicalUrlPath($cmsPage)); } $targetPath->setData('disabled', true); return $this; } /** * Get catalog entity associated stores * * @return array * @throws \Magento\Framework\Exception\LocalizedException */ protected function _getEntityStores() { $cmsPage = $this->_getCmsPage(); $entityStores = []; // showing websites that only associated to CMS page if ($this->_getCmsPage()->getId()) { $entityStores = (array)$cmsPage->getResource()->lookupStoreIds($cmsPage->getId()); $this->_requireStoresFilter = !in_array(0, $entityStores); if (!$entityStores) { throw new \Magento\Framework\Exception\LocalizedException( __('Please assign a website to the selected CMS page.') ); } } return $entityStores; } /** * Get CMS page model instance * * @return \Magento\Cms\Model\Page */ protected function _getCmsPage() { if (!$this->hasData('cms_page')) { $this->setCmsPage($this->_pageFactory->create()); } return $this->getCmsPage(); } }