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

Public Member Functions

 __construct (\Magento\Framework\View\Element\Template\Context $context, \Magento\Catalog\Model\CategoryFactory $categoryFactory, \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory, \Magento\Catalog\Model\Layer\Resolver $layerResolver, \Magento\Framework\App\Http\Context $httpContext, \Magento\Catalog\Helper\Category $catalogCategory, \Magento\Framework\Registry $registry, \Magento\Catalog\Model\Indexer\Category\Flat\State $flatState, array $data=[])
 
 getCategory ()
 
 getCacheKeyInfo ()
 
 getCurrentCategoryKey ()
 
 isCategoryActive ($category)
 
 getCategoryUrl ($category)
 
 getCurrentCategory ()
 
 getIdentities ()
 
- 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

 _construct ()
 
- 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

 $_categoryInstance
 
 $_currentCategoryKey
 
 $_itemLevelPositions = []
 
 $_catalogCategory
 
 $_registry
 
 $httpContext
 
 $_catalogLayer
 
 $_productCollectionFactory
 
 $flatState
 
- 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

Catalog navigation

@api @SuppressWarnings(PHPMD.LongVariable) @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Since
100.0.2

Definition at line 20 of file Navigation.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\View\Element\Template\Context  $context,
\Magento\Catalog\Model\CategoryFactory  $categoryFactory,
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory  $productCollectionFactory,
\Magento\Catalog\Model\Layer\Resolver  $layerResolver,
\Magento\Framework\App\Http\Context  $httpContext,
\Magento\Catalog\Helper\Category  $catalogCategory,
\Magento\Framework\Registry  $registry,
\Magento\Catalog\Model\Indexer\Category\Flat\State  $flatState,
array  $data = [] 
)
Parameters
\Magento\Framework\View\Element\Template\Context$context
\Magento\Catalog\Model\CategoryFactory$categoryFactory
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory$productCollectionFactory
\Magento\Catalog\Model\Layer\Resolver$layerResolver
\Magento\Framework\App\Http\Context$httpContext
\Magento\Catalog\Helper\Category$catalogCategory
\Magento\Framework\Registry$registry
\Magento\Catalog\Model\Indexer\Category\Flat\State$flatState
array$data

Definition at line 91 of file Navigation.php.

101  {
102  $this->_productCollectionFactory = $productCollectionFactory;
103  $this->_catalogLayer = $layerResolver->get();
104  $this->httpContext = $httpContext;
105  $this->_catalogCategory = $catalogCategory;
106  $this->_registry = $registry;
107  $this->flatState = $flatState;
108  $this->_categoryInstance = $categoryFactory->create();
109  parent::__construct($context, $data);
110  }

Member Function Documentation

◆ _construct()

_construct ( )
protected
Returns
void

Definition at line 115 of file Navigation.php.

116  {
117  $this->addData(
118  [
119  'cache_lifetime' => false,
120  'cache_tags' => [Category::CACHE_TAG, \Magento\Store\Model\Group::CACHE_TAG],
121  ]
122  );
123  }

◆ getCacheKeyInfo()

getCacheKeyInfo ( )

Get Key pieces for caching block content

Returns
array

Definition at line 140 of file Navigation.php.

141  {
142  $shortCacheId = [
143  'CATALOG_NAVIGATION',
144  $this->_storeManager->getStore()->getId(),
145  $this->_design->getDesignTheme()->getId(),
146  $this->httpContext->getValue(Context::CONTEXT_GROUP),
147  'template' => $this->getTemplate(),
148  'name' => $this->getNameInLayout(),
149  $this->getCurrentCategoryKey(),
150  ];
151  $cacheId = $shortCacheId;
152 
153  $shortCacheId = array_values($shortCacheId);
154  $shortCacheId = implode('|', $shortCacheId);
155  $shortCacheId = md5($shortCacheId);
156 
157  $cacheId['category_path'] = $this->getCurrentCategoryKey();
158  $cacheId['short_cache_id'] = $shortCacheId;
159 
160  return $cacheId;
161  }

◆ getCategory()

getCategory ( )

Get current category

Returns
Category

Definition at line 130 of file Navigation.php.

131  {
132  return $this->_registry->registry('current_category');
133  }

◆ getCategoryUrl()

getCategoryUrl (   $category)

Get url for category data

Parameters
Category$category
Returns
string

Definition at line 217 of file Navigation.php.

218  {
219  if ($category instanceof Category) {
220  $url = $category->getUrl();
221  } else {
222  $url = $this->_categoryInstance->setData($category->getData())->getUrl();
223  }
224 
225  return $url;
226  }

◆ getCurrentCategory()

getCurrentCategory ( )

Enter description here...

Returns
Category

Definition at line 233 of file Navigation.php.

234  {
235  return $this->_catalogLayer->getCurrentCategory();
236  }

◆ getCurrentCategoryKey()

getCurrentCategoryKey ( )

Get current category key

Returns
string

Definition at line 168 of file Navigation.php.

169  {
170  if (!$this->_currentCategoryKey) {
171  $category = $this->_registry->registry('current_category');
172  if ($category) {
173  $this->_currentCategoryKey = $category->getPath();
174  } else {
175  $this->_currentCategoryKey = $this->_storeManager->getStore()->getRootCategoryId();
176  }
177  }
178 
180  }

◆ getIdentities()

getIdentities ( )

Return identifiers for produced content

Returns
array

Implements IdentityInterface.

Definition at line 243 of file Navigation.php.

◆ isCategoryActive()

isCategoryActive (   $category)

Check activity of category

Parameters
\Magento\Framework\DataObject$category
Returns
bool

Definition at line 203 of file Navigation.php.

204  {
205  if ($this->getCurrentCategory()) {
206  return in_array($category->getId(), $this->getCurrentCategory()->getPathIds());
207  }
208  return false;
209  }

Field Documentation

◆ $_catalogCategory

$_catalogCategory
protected

Definition at line 47 of file Navigation.php.

◆ $_catalogLayer

$_catalogLayer
protected

Definition at line 66 of file Navigation.php.

◆ $_categoryInstance

$_categoryInstance
protected

Definition at line 26 of file Navigation.php.

◆ $_currentCategoryKey

$_currentCategoryKey
protected

Definition at line 33 of file Navigation.php.

◆ $_itemLevelPositions

$_itemLevelPositions = []
protected

Definition at line 40 of file Navigation.php.

◆ $_productCollectionFactory

$_productCollectionFactory
protected

Definition at line 73 of file Navigation.php.

◆ $_registry

$_registry
protected

Definition at line 52 of file Navigation.php.

◆ $flatState

$flatState
protected

Definition at line 78 of file Navigation.php.

◆ $httpContext

$httpContext
protected

Definition at line 59 of file Navigation.php.


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