/** * Form post init * * @param \Magento\Framework\Data\Form $form * @return $this */ protected function _formPostInit($form) { $form->setAction($this->_adminhtmlData->getUrl('adminhtml/*/save', array('id' => $this->_getModel()->getId(), 'product' => $this->_getProduct()->getId(), 'category' => $this->_getCategory()->getId()))); /** @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(); $disablePaths = false; if (!$model->getId()) { $product = null; $category = null; if ($this->_getProduct()->getId()) { $product = $this->_getProduct(); $category = $this->_getCategory(); } elseif ($this->_getCategory()->getId()) { $category = $this->_getCategory(); } if ($product || $category) { $sessionData = $this->_getSessionData(); if (!isset($sessionData['request_path'])) { $requestPath->setValue($this->_catalogUrl->generatePath('request', $product, $category, '')); } $targetPath->setValue($this->_catalogUrl->generatePath('target', $product, $category)); $disablePaths = true; } } else { $disablePaths = in_array($model->getEntityType(), [UrlRedirect::ENTITY_TYPE_PRODUCT, UrlRedirect::ENTITY_TYPE_CATEGORY, UrlRedirect::ENTITY_TYPE_CMS_PAGE]); } if ($disablePaths) { $targetPath->setData('disabled', true); } return $this; }
/** * Form post init * * @param \Magento\Framework\Data\Form $form * @return \Magento\UrlRedirect\Block\Cms\Page\Edit\Form */ protected function _formPostInit($form) { $cmsPage = $this->_getCmsPage(); $form->setAction($this->_adminhtmlData->getUrl('adminhtml/*/save', array('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(); /** @var $cmsPageUrlrewrite \Magento\Cms\Model\Page\Urlrewrite */ $cmsPageUrlrewrite = $this->_urlRewriteFactory->create(); if (!$model->getId()) { $sessionData = $this->_getSessionData(); if (!isset($sessionData['request_path'])) { $requestPath->setValue($cmsPageUrlrewrite->generateRequestPath($cmsPage)); } $targetPath->setValue($cmsPageUrlrewrite->generateTargetPath($cmsPage)); $disablePaths = true; } else { $cmsPageUrlrewrite->load($this->_getModel()->getId(), 'url_rewrite_id'); $disablePaths = $cmsPageUrlrewrite->getId() > 0; } if ($disablePaths) { $targetPath->setData('disabled', true); } return $this; }
/** * 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; }
/** * Form post init * * @param \Magento\Framework\Data\Form $form * @return $this */ protected function _formPostInit($form) { $form->setAction($this->_adminhtmlData->getUrl('adminhtml/*/save', ['id' => $this->_getModel()->getId()])); return $this; }
/** * Form post init * * @param \Magento\Framework\Data\Form $form * @return \Magento\Backend\Block\Urlrewrite\Catalog\Edit\Form */ protected function _formPostInit($form) { // Set form action $form->setAction($this->_adminhtmlData->getUrl('adminhtml/*/save', array('id' => $this->_getModel()->getId(), 'product' => $this->_getProduct()->getId(), 'category' => $this->_getCategory()->getId()))); // Fill id path, request path and target path elements /** @var $idPath \Magento\Framework\Data\Form\Element\AbstractElement */ $idPath = $this->getForm()->getElement('id_path'); /** @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(); $disablePaths = false; if (!$model->getId()) { $product = null; $category = null; if ($this->_getProduct()->getId()) { $product = $this->_getProduct(); $category = $this->_getCategory(); } elseif ($this->_getCategory()->getId()) { $category = $this->_getCategory(); } if ($product || $category) { $idPath->setValue($this->_catalogUrl->generatePath('id', $product, $category)); $sessionData = $this->_getSessionData(); if (!isset($sessionData['request_path'])) { $requestPath->setValue($this->_catalogUrl->generatePath('request', $product, $category, '')); } $targetPath->setValue($this->_catalogUrl->generatePath('target', $product, $category)); $disablePaths = true; } } else { $disablePaths = $model->getProductId() || $model->getCategoryId(); } // Disable id_path and target_path elements if ($disablePaths) { $idPath->setData('disabled', true); $targetPath->setData('disabled', true); } return $this; }