Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Rewrite.php
Go to the documentation of this file.
1 <?php
7 
11 
15 abstract class Rewrite extends Action
16 {
22  const ADMIN_RESOURCE = 'Magento_UrlRewrite::urlrewrite';
23 
27  const ENTITY_TYPE_CUSTOM = 'custom';
28  const ENTITY_TYPE_PRODUCT = 'product';
29  const ENTITY_TYPE_CATEGORY = 'category';
30  const ENTITY_TYPE_CMS_PAGE = 'cms-page';
34  protected $_product;
35 
39  protected $_category;
40 
44  protected $_cmsPage;
45 
49  protected $_urlRewrite;
50 
56  protected function _getCategory()
57  {
58  if (!$this->_category) {
59  $this->_category = $this->_objectManager->create(\Magento\Catalog\Model\Category::class);
60  $categoryId = (int)$this->getRequest()->getParam('category', 0);
61  $urlRewrite = $this->_getUrlRewrite();
62  if (!$categoryId && $urlRewrite->getId()) {
63  $metaData = $urlRewrite->getMetadata();
64  if ($urlRewrite->getEntityType() === self::ENTITY_TYPE_CATEGORY) {
65  $categoryId = $urlRewrite->getEntityId();
66  } elseif (!empty($metaData['category_id'])) {
67  $categoryId = $metaData['category_id'];
68  }
69  }
70  if ($categoryId) {
71  $this->_category->load($categoryId);
72  }
73  }
74  return $this->_category;
75  }
76 
82  protected function _getProduct()
83  {
84  if (!$this->_product) {
85  $this->_product = $this->_objectManager->create(\Magento\Catalog\Model\Product::class);
86  $productId = (int)$this->getRequest()->getParam('product', 0);
87  $urlRewrite = $this->_getUrlRewrite();
88  if (!$productId && $urlRewrite->getId() && $urlRewrite->getEntityType() === self::ENTITY_TYPE_PRODUCT) {
89  $productId = $this->_getUrlRewrite()->getEntityId();
90  }
91  if ($productId) {
92  $this->_product->load($productId);
93  }
94  }
95  return $this->_product;
96  }
97 
103  protected function _getCmsPage()
104  {
105  if (!$this->_cmsPage) {
106  $this->_cmsPage = $this->_objectManager->create(\Magento\Cms\Model\Page::class);
107  $cmsPageId = (int)$this->getRequest()->getParam('cms_page', 0);
108  $urlRewrite = $this->_getUrlRewrite();
109  if (!$cmsPageId && $urlRewrite->getId() && $urlRewrite->getEntityType() === self::ENTITY_TYPE_CMS_PAGE) {
110  $cmsPageId = $this->_getUrlRewrite()->getEntityId();
111  }
112  if ($cmsPageId) {
113  $this->_cmsPage->load($cmsPageId);
114  }
115  }
116  return $this->_cmsPage;
117  }
118 
124  protected function _getUrlRewrite()
125  {
126  if (!$this->_urlRewrite) {
127  $this->_urlRewrite = $this->_objectManager->create(\Magento\UrlRewrite\Model\UrlRewrite::class);
128  $urlRewriteId = (int)$this->getRequest()->getParam('id', 0);
129  if ($urlRewriteId) {
130  $this->_urlRewrite->load($urlRewriteId);
131  }
132  }
133  return $this->_urlRewrite;
134  }
135 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17