51 parent::__construct($context);
70 if (
$model->isObjectNew()) {
71 $model->setEntityType(
$productId ? self::ENTITY_TYPE_PRODUCT : self::ENTITY_TYPE_CATEGORY)
74 $model->setMetadata([
'category_id' => $categoryId]);
91 if (
$model->getRedirectType() && !
$model->getIsAutogenerated()) {
101 ?
__(
"The selected product isn't associated with the selected store or category.")
102 :
__(
"The selected category isn't associated with the selected store.");
105 $targetPath =
$rewrite->getRequestPath();
119 : $this->categoryUrlPathGenerator->getCanonicalUrlPath(
$category);
128 private function _handleCmsPageUrlRewrite(
$model)
131 if ($cmsPage->getId()) {
132 if (
$model->isObjectNew()) {
133 $model->setEntityType(self::ENTITY_TYPE_CMS_PAGE)->setEntityId($cmsPage->getId());
135 if (
$model->getRedirectType() && !
$model->getIsAutogenerated()) {
136 $targetPath = $this->cmsPageUrlPathGenerator->getUrlPath($cmsPage);
138 $targetPath = $this->cmsPageUrlPathGenerator->getCanonicalUrlPath($cmsPage);
140 $model->setTargetPath($targetPath);
152 $session = $this->_objectManager->get(\
Magento\Backend\Model\Session::class);
156 $requestPath = $this->
getRequest()->getParam(
'request_path');
157 $this->_objectManager->get(
158 \
Magento\UrlRewrite\Helper\UrlRewrite::class
159 )->validateRequestPath($requestPath);
161 $model->setEntityType($this->
getRequest()->getParam(
'entity_type') ?: self::ENTITY_TYPE_CUSTOM)
162 ->setRequestPath($requestPath)
163 ->setTargetPath($this->
getRequest()->getParam(
'target_path',
$model->getTargetPath()))
164 ->setRedirectType($this->
getRequest()->getParam(
'redirect_type'))
165 ->setStoreId($this->
getRequest()->getParam(
'store_id', 0))
166 ->setDescription($this->
getRequest()->getParam(
'description'));
169 $this->_handleCmsPageUrlRewrite(
$model);
172 $this->messageManager->addSuccess(
__(
'The URL Rewrite has been saved.'));
175 }
catch (LocalizedException $e) {
176 $this->messageManager->addError($e->getMessage());
178 }
catch (\Exception $e) {
179 $this->messageManager->addException(
181 __(
'An error occurred while saving the URL rewrite. Please try to save again.')
_handleCatalogUrlRewrite($model)
_redirect($path, $arguments=[])
$categoryUrlPathGenerator
__construct(\Magento\Backend\App\Action\Context $context, \Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator $productUrlPathGenerator, \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator, \Magento\CmsUrlRewrite\Model\CmsPageUrlPathGenerator $cmsPageUrlPathGenerator, UrlFinderInterface $urlFinder)