Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
AbstractCategory Class Reference
Inheritance diagram for AbstractCategory:
Template Template AbstractBlock DataObject BlockInterface DeleteButton SaveButton Tree Tree Tree Chooser Chooser

Public Member Functions

 __construct (\Magento\Backend\Block\Template\Context $context, \Magento\Catalog\Model\ResourceModel\Category\Tree $categoryTree, \Magento\Framework\Registry $registry, \Magento\Catalog\Model\CategoryFactory $categoryFactory, array $data=[])
 
 getCategory ()
 
 getCategoryId ()
 
 getCategoryName ()
 
 getCategoryPath ()
 
 hasStoreRootCategory ()
 
 getStore ()
 
 getRoot ($parentNodeCategory=null, $recursionLevel=3)
 
 getCategoryCollection ()
 
 getRootByIds ($ids)
 
 getNode ($parentNodeCategory, $recursionLevel=2)
 
 getSaveUrl (array $args=[])
 
 getEditUrl ()
 
 getRootIds ()
 
- Public Member Functions inherited from Template
 __construct (\Magento\Backend\Block\Template\Context $context, array $data=[])
 
 getFormKey ()
 
 isOutputEnabled ($moduleName=null)
 
 getAuthorization ()
 
 getToolbar ()
 
- Public Member Functions inherited from Template
 __construct (Template\Context $context, array $data=[])
 
 setTemplateContext ($templateContext)
 
 getTemplate ()
 
 setTemplate ($template)
 
 getTemplateFile ($template=null)
 
 getArea ()
 
 assign ($key, $value=null)
 
 fetchView ($fileName)
 
 getBaseUrl ()
 
 getObjectData (\Magento\Framework\DataObject $object, $key)
 
 getCacheKeyInfo ()
 
- Public Member Functions inherited from AbstractBlock
 __construct (\Magento\Framework\View\Element\Context $context, array $data=[])
 
 getJsLayout ()
 
 getRequest ()
 
 getParentBlock ()
 
 setLayout (\Magento\Framework\View\LayoutInterface $layout)
 
 getLayout ()
 
 setNameInLayout ($name)
 
 getChildNames ()
 
 setAttribute ($name, $value=null)
 
 setChild ($alias, $block)
 
 addChild ($alias, $block, $data=[])
 
 unsetChild ($alias)
 
 unsetCallChild ($alias, $callback, $result, $params)
 
 unsetChildren ()
 
 getChildBlock ($alias)
 
 getChildHtml ($alias='', $useCache=true)
 
 getChildChildHtml ($alias, $childChildAlias='', $useCache=true)
 
 getBlockHtml ($name)
 
 insert ($element, $siblingName=0, $after=true, $alias='')
 
 append ($element, $alias='')
 
 getGroupChildNames ($groupName)
 
 getChildData ($alias, $key='')
 
 getUiId ($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)
 
 getJsId ($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)
 
 getUrl ($route='', $params=[])
 
 getViewFileUrl ($fileId, array $params=[])
 
 formatDate ( $date=null, $format=\IntlDateFormatter::SHORT, $showTime=false, $timezone=null)
 
 formatTime ( $time=null, $format=\IntlDateFormatter::SHORT, $showDate=false)
 
 getModuleName ()
 
 escapeHtml ($data, $allowedTags=null)
 
 escapeJs ($string)
 
 escapeHtmlAttr ($string, $escapeSingleQuote=true)
 
 escapeCss ($string)
 
 stripTags ($data, $allowableTags=null, $allowHtmlEntities=false)
 
 escapeUrl ($string)
 
 escapeXssInUrl ($data)
 
 escapeQuote ($data, $addSlashes=false)
 
 escapeJsQuote ($data, $quote='\'')
 
 getNameInLayout ()
 
 getCacheKeyInfo ()
 
 getCacheKey ()
 
 getVar ($name, $module=null)
 
 isScopePrivate ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 
- Public Member Functions inherited from BlockInterface
 toHtml ()
 

Protected Member Functions

 _getDefaultStoreId ()
 
- Protected Member Functions inherited from Template
 _toHtml ()
 
- Protected Member Functions inherited from Template
 _construct ()
 
 _toHtml ()
 
 getRootDirectory ()
 
 getMediaDirectory ()
 
- Protected Member Functions inherited from AbstractBlock
 _construct ()
 
 _prepareLayout ()
 
 _beforeToHtml ()
 
 _afterToHtml ($html)
 
 _toHtml ()
 
 _getNotFoundUrl ($route='', $params=['_direct'=> 'core/index/notFound'])
 
 getCacheTags ()
 
 getCacheLifetime ()
 
 _loadCache ()
 
 _saveCache ($data)
 
 _getSidPlaceholder ($cacheKey=null)
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_coreRegistry = null
 
 $_categoryTree
 
 $_categoryFactory
 
 $_withProductCount
 
- Protected Attributes inherited from Template
 $_authorization
 
 $mathRandom
 
 $_backendSession
 
 $formKey
 
 $nameBuilder
 
- Protected Attributes inherited from Template
 $_viewVars = []
 
 $_baseUrl
 
 $_jsUrl
 
 $_allowSymlinks
 
 $_filesystem
 
 $_template
 
 $templateEnginePool
 
 $_storeManager
 
 $_appState
 
 $directory
 
 $templateContext
 
 $pageConfig
 
 $resolver
 
 $validator
 
- Protected Attributes inherited from AbstractBlock
 $_design
 
 $_session
 
 $_sidResolver
 
 $_nameInLayout
 
 $_layout
 
 $jsLayout = []
 
 $_request
 
 $_urlBuilder
 
 $_eventManager
 
 $_frontController
 
 $_assetRepo
 
 $_viewConfig
 
 $_cacheState
 
 $_logger
 
 $_escaper
 
 $filterManager
 
 $_localeDate
 
 $inlineTranslation
 
 $_isScopePrivate = false
 
 $_scopeConfig
 
 $_cache
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Public Member Functions inherited from AbstractBlock
static extractModuleName ($className)
 
- Data Fields inherited from Template
const XML_PATH_TEMPLATE_ALLOW_SYMLINK = 'dev/template/allow_symlink'
 
- Data Fields inherited from AbstractBlock
const CACHE_GROUP = \Magento\Framework\App\Cache\Type\Block::TYPE_IDENTIFIER
 
const CACHE_KEY_PREFIX = 'BLOCK_'
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Class AbstractCategory

Definition at line 14 of file AbstractCategory.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Backend\Block\Template\Context  $context,
\Magento\Catalog\Model\ResourceModel\Category\Tree  $categoryTree,
\Magento\Framework\Registry  $registry,
\Magento\Catalog\Model\CategoryFactory  $categoryFactory,
array  $data = [] 
)
Parameters
\Magento\Backend\Block\Template\Context$context
\Magento\Catalog\Model\ResourceModel\Category\Tree$categoryTree
\Magento\Framework\Registry$registry
\Magento\Catalog\Model\CategoryFactory$categoryFactory
array$data

Definition at line 45 of file AbstractCategory.php.

51  {
52  $this->_categoryTree = $categoryTree;
53  $this->_coreRegistry = $registry;
54  $this->_categoryFactory = $categoryFactory;
55  $this->_withProductCount = true;
56  parent::__construct($context, $data);
57  }

Member Function Documentation

◆ _getDefaultStoreId()

_getDefaultStoreId ( )
protected
Returns
int

Definition at line 167 of file AbstractCategory.php.

168  {
169  return \Magento\Store\Model\Store::DEFAULT_STORE_ID;
170  }

◆ getCategory()

getCategory ( )

Retrieve current category instance

Returns
array|null

Definition at line 64 of file AbstractCategory.php.

65  {
66  return $this->_coreRegistry->registry('category');
67  }

◆ getCategoryCollection()

getCategoryCollection ( )
Returns
\Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection

Definition at line 175 of file AbstractCategory.php.

176  {
177  $storeId = $this->getRequest()->getParam('store', $this->_getDefaultStoreId());
178  $collection = $this->getData('category_collection');
179  if ($collection === null) {
180  $collection = $this->_categoryFactory->create()->getCollection();
181 
182  $collection->addAttributeToSelect(
183  'name'
184  )->addAttributeToSelect(
185  'is_active'
186  )->setProductStoreId(
187  $storeId
188  )->setLoadProductCount(
189  $this->_withProductCount
190  )->setStoreId(
191  $storeId
192  );
193 
194  $this->setData('category_collection', $collection);
195  }
196  return $collection;
197  }
getData($key='', $index=null)
Definition: DataObject.php:119
setData($key, $value=null)
Definition: DataObject.php:72

◆ getCategoryId()

getCategoryId ( )
Returns
int|string|null

Definition at line 72 of file AbstractCategory.php.

73  {
74  if ($this->getCategory()) {
75  return $this->getCategory()->getId();
76  }
77  return \Magento\Catalog\Model\Category::TREE_ROOT_ID;
78  }

◆ getCategoryName()

getCategoryName ( )
Returns
string

Definition at line 83 of file AbstractCategory.php.

84  {
85  return $this->getCategory()->getName();
86  }

◆ getCategoryPath()

getCategoryPath ( )
Returns
mixed

Definition at line 91 of file AbstractCategory.php.

92  {
93  if ($this->getCategory()) {
94  return $this->getCategory()->getPath();
95  }
96  return \Magento\Catalog\Model\Category::TREE_ROOT_ID;
97  }

◆ getEditUrl()

getEditUrl ( )
Returns
string

Definition at line 265 of file AbstractCategory.php.

266  {
267  return $this->getUrl(
268  'catalog/category/edit',
269  ['store' => null, '_query' => false, 'id' => null, 'parent' => null]
270  );
271  }

◆ getNode()

getNode (   $parentNodeCategory,
  $recursionLevel = 2 
)
Parameters
mixed$parentNodeCategory
int$recursionLevel
Returns
Node

Definition at line 234 of file AbstractCategory.php.

235  {
236  $nodeId = $parentNodeCategory->getId();
237  $node = $this->_categoryTree->loadNode($nodeId);
238  $node->loadChildren($recursionLevel);
239 
240  if ($node && $nodeId != \Magento\Catalog\Model\Category::TREE_ROOT_ID) {
241  $node->setIsVisible(true);
242  } elseif ($node && $node->getId() == \Magento\Catalog\Model\Category::TREE_ROOT_ID) {
243  $node->setName(__('Root'));
244  }
245 
246  $this->_categoryTree->addCollectionData($this->getCategoryCollection());
247 
248  return $node;
249  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13

◆ getRoot()

getRoot (   $parentNodeCategory = null,
  $recursionLevel = 3 
)
Parameters
mixed | null$parentNodeCategory
int$recursionLevel
Returns
Node|array|null @SuppressWarnings(PHPMD.CyclomaticComplexity)

Definition at line 126 of file AbstractCategory.php.

127  {
128  if ($parentNodeCategory !== null && $parentNodeCategory->getId()) {
129  return $this->getNode($parentNodeCategory, $recursionLevel);
130  }
131  $root = $this->_coreRegistry->registry('root');
132  if ($root === null) {
133  $storeId = (int)$this->getRequest()->getParam('store');
134 
135  if ($storeId) {
136  $store = $this->_storeManager->getStore($storeId);
137  $rootId = $store->getRootCategoryId();
138  } else {
140  }
141 
142  $tree = $this->_categoryTree->load(null, $recursionLevel);
143 
144  if ($this->getCategory()) {
145  $tree->loadEnsuredNodes($this->getCategory(), $tree->getNodeById($rootId));
146  }
147 
148  $tree->addCollectionData($this->getCategoryCollection());
149 
150  $root = $tree->getNodeById($rootId);
151 
152  if ($root && $rootId != \Magento\Catalog\Model\Category::TREE_ROOT_ID) {
153  $root->setIsVisible(true);
154  } elseif ($root && $root->getId() == \Magento\Catalog\Model\Category::TREE_ROOT_ID) {
155  $root->setName(__('Root'));
156  }
157 
158  $this->_coreRegistry->register('root', $root);
159  }
160 
161  return $root;
162  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13

◆ getRootByIds()

getRootByIds (   $ids)

Get and register categories root by specified categories IDs

IDs can be arbitrary set of any categories ids. Tree with minimal required nodes (all parents and neighbours) will be built. If ids are empty, default tree with depth = 2 will be returned.

Parameters
array$ids
Returns
mixed

Definition at line 209 of file AbstractCategory.php.

210  {
211  $root = $this->_coreRegistry->registry('root');
212  if (null === $root) {
213  $ids = $this->_categoryTree->getExistingCategoryIdsBySpecifiedIds($ids);
214  $tree = $this->_categoryTree->loadByIds($ids);
216  $root = $tree->getNodeById($rootId);
217  if ($root && $rootId != \Magento\Catalog\Model\Category::TREE_ROOT_ID) {
218  $root->setIsVisible(true);
219  } elseif ($root && $root->getId() == \Magento\Catalog\Model\Category::TREE_ROOT_ID) {
220  $root->setName(__('Root'));
221  }
222 
223  $tree->addCollectionData($this->getCategoryCollection());
224  $this->_coreRegistry->register('root', $root);
225  }
226  return $root;
227  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13

◆ getRootIds()

getRootIds ( )

Return ids of root categories as array

Returns
array

Definition at line 278 of file AbstractCategory.php.

279  {
280  $ids = $this->getData('root_ids');
281  if ($ids === null) {
283  foreach ($this->_storeManager->getGroups() as $store) {
284  $ids[] = $store->getRootCategoryId();
285  }
286  $this->setData('root_ids', $ids);
287  }
288  return $ids;
289  }
getData($key='', $index=null)
Definition: DataObject.php:119
setData($key, $value=null)
Definition: DataObject.php:72

◆ getSaveUrl()

getSaveUrl ( array  $args = [])
Parameters
array$args
Returns
string

Definition at line 255 of file AbstractCategory.php.

256  {
257  $params = ['_current' => false, '_query' => false, 'store' => $this->getStore()->getId()];
258  $params = array_merge($params, $args);
259  return $this->getUrl('catalog/*/save', $params);
260  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getStore()

getStore ( )
Returns
Store

Definition at line 114 of file AbstractCategory.php.

115  {
116  $storeId = (int)$this->getRequest()->getParam('store');
117  return $this->_storeManager->getStore($storeId);
118  }

◆ hasStoreRootCategory()

hasStoreRootCategory ( )
Returns
bool

Definition at line 102 of file AbstractCategory.php.

103  {
104  $root = $this->getRoot();
105  if ($root && $root->getId()) {
106  return true;
107  }
108  return false;
109  }
getRoot($parentNodeCategory=null, $recursionLevel=3)

Field Documentation

◆ $_categoryFactory

$_categoryFactory
protected

Definition at line 31 of file AbstractCategory.php.

◆ $_categoryTree

$_categoryTree
protected

Definition at line 26 of file AbstractCategory.php.

◆ $_coreRegistry

$_coreRegistry = null
protected

Definition at line 21 of file AbstractCategory.php.

◆ $_withProductCount

$_withProductCount
protected

Definition at line 36 of file AbstractCategory.php.


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