Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Save Class Reference
Inheritance diagram for Save:
Rewrite HttpPostActionInterface Action ActionInterface AbstractAction Action AbstractAction ActionInterface

Public Member Functions

 __construct (\Magento\Backend\App\Action\Context $context, \Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator $productUrlPathGenerator, \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator, \Magento\CmsUrlRewrite\Model\CmsPageUrlPathGenerator $cmsPageUrlPathGenerator, UrlFinderInterface $urlFinder)
 
- Public Member Functions inherited from AbstractAction
 __construct (Action\Context $context)
 
 dispatch (\Magento\Framework\App\RequestInterface $request)
 
 _processUrlKeys ()
 
 getUrl ($route='', $params=[])
 
- Public Member Functions inherited from Action
 __construct (Context $context)
 
 dispatch (RequestInterface $request)
 
 getActionFlag ()
 
- Public Member Functions inherited from AbstractAction
 __construct (Context $context)
 
 dispatch (RequestInterface $request)
 
 getRequest ()
 
 getResponse ()
 
- Public Member Functions inherited from ActionInterface
 execute ()
 

Protected Member Functions

 _handleCatalogUrlRewrite ($model)
 
 getTargetPath ($model)
 
 getCanonicalTargetPath ()
 
- Protected Member Functions inherited from Rewrite
 _getCategory ()
 
 _getProduct ()
 
 _getCmsPage ()
 
 _getUrlRewrite ()
 
- Protected Member Functions inherited from AbstractAction
 _isAllowed ()
 
 _getSession ()
 
 getMessageManager ()
 
 _addBreadcrumb ($label, $title, $link=null)
 
 _addContent (\Magento\Framework\View\Element\AbstractBlock $block)
 
 _addLeft (\Magento\Framework\View\Element\AbstractBlock $block)
 
 _addJs (\Magento\Framework\View\Element\AbstractBlock $block)
 
 _isUrlChecked ()
 
 _processLocaleSettings ()
 
 _redirect ($path, $arguments=[])
 
 _forward ($action, $controller=null, $module=null, array $params=null)
 
 _validateSecretKey ()
 
- Protected Member Functions inherited from Action
 _forward ($action, $controller=null, $module=null, array $params=null)
 
 _redirect ($path, $arguments=[])
 

Protected Attributes

 $productUrlPathGenerator
 
 $categoryUrlPathGenerator
 
 $cmsPageUrlPathGenerator
 
 $urlFinder
 
- Protected Attributes inherited from Rewrite
 $_product
 
 $_category
 
 $_cmsPage
 
 $_urlRewrite
 
- Protected Attributes inherited from AbstractAction
 $_publicActions = []
 
 $_sessionNamespace = self::SESSION_NAMESPACE
 
 $_helper
 
 $_session
 
 $_authorization
 
 $_auth
 
 $_backendUrl
 
 $_localeResolver
 
 $_canUseBaseUrl
 
 $_formKeyValidator
 
- Protected Attributes inherited from Action
 $_objectManager
 
 $_sessionNamespace
 
 $_eventManager
 
 $_actionFlag
 
 $_redirect
 
 $_view
 
 $_url
 
 $messageManager
 
- Protected Attributes inherited from AbstractAction
 $_request
 
 $_response
 
 $resultRedirectFactory
 
 $resultFactory
 

Additional Inherited Members

- Data Fields inherited from Rewrite
const ADMIN_RESOURCE = 'Magento_UrlRewrite::urlrewrite'
 
const ENTITY_TYPE_CUSTOM = 'custom'
 
const ENTITY_TYPE_PRODUCT = 'product'
 
const ENTITY_TYPE_CATEGORY = 'category'
 
const ENTITY_TYPE_CMS_PAGE = 'cms-page'
 
- Data Fields inherited from AbstractAction
const FLAG_IS_URLS_CHECKED = 'check_url_settings'
 
const SESSION_NAMESPACE = 'adminhtml'
 
const ADMIN_RESOURCE = 'Magento_Backend::admin'
 
- Data Fields inherited from ActionInterface
const FLAG_NO_DISPATCH = 'no-dispatch'
 
const FLAG_NO_POST_DISPATCH = 'no-postDispatch'
 
const FLAG_NO_DISPATCH_BLOCK_EVENT = 'no-beforeGenerateLayoutBlocksDispatch'
 
const PARAM_NAME_BASE64_URL = 'r64'
 
const PARAM_NAME_URL_ENCODED = 'uenc'
 

Detailed Description

Definition at line 15 of file Save.php.

Constructor & Destructor Documentation

◆ __construct()

Parameters
\Magento\Backend\App\Action\Context$context
\Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator$productUrlPathGenerator
\Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator$categoryUrlPathGenerator
\Magento\CmsUrlRewrite\Model\CmsPageUrlPathGenerator$cmsPageUrlPathGenerator
UrlFinderInterface$urlFinder

Definition at line 44 of file Save.php.

50  {
51  parent::__construct($context);
52  $this->productUrlPathGenerator = $productUrlPathGenerator;
53  $this->categoryUrlPathGenerator = $categoryUrlPathGenerator;
54  $this->cmsPageUrlPathGenerator = $cmsPageUrlPathGenerator;
55  $this->urlFinder = $urlFinder;
56  }

Member Function Documentation

◆ _handleCatalogUrlRewrite()

_handleCatalogUrlRewrite (   $model)
protected

Override urlrewrite data, basing on current category and product

Parameters
\Magento\UrlRewrite\Model\UrlRewrite$model
Returns
void
Exceptions

Definition at line 65 of file Save.php.

66  {
67  $productId = $this->_getProduct()->getId();
68  $categoryId = $this->_getCategory()->getId();
69  if ($productId || $categoryId) {
70  if ($model->isObjectNew()) {
71  $model->setEntityType($productId ? self::ENTITY_TYPE_PRODUCT : self::ENTITY_TYPE_CATEGORY)
72  ->setEntityId($productId ?: $categoryId);
73  if ($productId && $categoryId) {
74  $model->setMetadata(['category_id' => $categoryId]);
75  }
76  }
77  $model->setTargetPath($this->getTargetPath($model));
78  }
79  }

◆ getCanonicalTargetPath()

getCanonicalTargetPath ( )
protected
Returns
string

Definition at line 113 of file Save.php.

114  {
115  $product = $this->_getProduct()->getId() ? $this->_getProduct() : null;
116  $category = $this->_getCategory()->getId() ? $this->_getCategory() : null;
117  return $product
118  ? $this->productUrlPathGenerator->getCanonicalUrlPath($product, $category)
119  : $this->categoryUrlPathGenerator->getCanonicalUrlPath($category);
120  }

◆ getTargetPath()

getTargetPath (   $model)
protected

Get Target Path

Parameters
\Magento\UrlRewrite\Model\UrlRewrite$model
Returns
string
Exceptions

Definition at line 88 of file Save.php.

89  {
90  $targetPath = $this->getCanonicalTargetPath();
91  if ($model->getRedirectType() && !$model->getIsAutogenerated()) {
92  $data = [
93  UrlRewrite::ENTITY_ID => $model->getEntityId(),
94  UrlRewrite::TARGET_PATH => $targetPath,
95  UrlRewrite::ENTITY_TYPE => $model->getEntityType(),
96  UrlRewrite::STORE_ID => $model->getStoreId(),
97  ];
98  $rewrite = $this->urlFinder->findOneByData($data);
99  if (!$rewrite) {
100  $message = $model->getEntityType() === self::ENTITY_TYPE_PRODUCT
101  ? __("The selected product isn't associated with the selected store or category.")
102  : __("The selected category isn't associated with the selected store.");
103  throw new LocalizedException($message);
104  }
105  $targetPath = $rewrite->getRequestPath();
106  }
107  return $targetPath;
108  }
__()
Definition: __.php:13
$message

Field Documentation

◆ $categoryUrlPathGenerator

$categoryUrlPathGenerator
protected

Definition at line 25 of file Save.php.

◆ $cmsPageUrlPathGenerator

$cmsPageUrlPathGenerator
protected

Definition at line 30 of file Save.php.

◆ $productUrlPathGenerator

$productUrlPathGenerator
protected

Definition at line 20 of file Save.php.

◆ $urlFinder

$urlFinder
protected

Definition at line 35 of file Save.php.


The documentation for this class was generated from the following file: