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

Public Member Functions

 __construct (\Magento\Framework\View\Element\Template\Context $context, \Magento\Catalog\Model\Layer\Resolver $layerResolver, \Magento\Framework\Registry $registry, \Magento\Catalog\Helper\Category $categoryHelper, array $data=[])
 
 getProductListHtml ()
 
 getCurrentCategory ()
 
 getCmsBlockHtml ()
 
 isProductMode ()
 
 isMixedMode ()
 
 isContentMode ()
 
 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

 _prepareLayout ()
 
- 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
 
 $_catalogLayer
 
 $_categoryHelper
 
- 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

Definition at line 14 of file View.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\View\Element\Template\Context  $context,
\Magento\Catalog\Model\Layer\Resolver  $layerResolver,
\Magento\Framework\Registry  $registry,
\Magento\Catalog\Helper\Category  $categoryHelper,
array  $data = [] 
)
Parameters
\Magento\Framework\View\Element\Template\Context$context
\Magento\Catalog\Model\Layer\Resolver$layerResolver
\Magento\Framework\Registry$registry
\Magento\Catalog\Helper\Category$categoryHelper
array$data

Definition at line 42 of file View.php.

48  {
49  $this->_categoryHelper = $categoryHelper;
50  $this->_catalogLayer = $layerResolver->get();
51  $this->_coreRegistry = $registry;
52  parent::__construct($context, $data);
53  }

Member Function Documentation

◆ _prepareLayout()

_prepareLayout ( )
protected
Returns
$this

Definition at line 58 of file View.php.

59  {
60  parent::_prepareLayout();
61 
62  $this->getLayout()->createBlock(\Magento\Catalog\Block\Breadcrumbs::class);
63 
64  $category = $this->getCurrentCategory();
65  if ($category) {
66  $title = $category->getMetaTitle();
67  if ($title) {
68  $this->pageConfig->getTitle()->set($title);
69  }
70  $description = $category->getMetaDescription();
71  if ($description) {
72  $this->pageConfig->setDescription($description);
73  }
74  $keywords = $category->getMetaKeywords();
75  if ($keywords) {
76  $this->pageConfig->setKeywords($keywords);
77  }
78  if ($this->_categoryHelper->canUseCanonicalTag()) {
79  $this->pageConfig->addRemotePageAsset(
80  $category->getUrl(),
81  'canonical',
82  ['attributes' => ['rel' => 'canonical']]
83  );
84  }
85 
86  $pageMainTitle = $this->getLayout()->getBlock('page.main.title');
87  if ($pageMainTitle) {
88  $pageMainTitle->setPageTitle($this->getCurrentCategory()->getName());
89  }
90  }
91 
92  return $this;
93  }
$title
Definition: default.phtml:14

◆ getCmsBlockHtml()

getCmsBlockHtml ( )
Returns
mixed

Definition at line 119 of file View.php.

120  {
121  if (!$this->getData('cms_block_html')) {
122  $html = $this->getLayout()->createBlock(
123  \Magento\Cms\Block\Block::class
124  )->setBlockId(
125  $this->getCurrentCategory()->getLandingPage()
126  )->toHtml();
127  $this->setData('cms_block_html', $html);
128  }
129  return $this->getData('cms_block_html');
130  }
getData($key='', $index=null)
Definition: DataObject.php:119
setData($key, $value=null)
Definition: DataObject.php:72

◆ getCurrentCategory()

getCurrentCategory ( )

Retrieve current category model object

Returns
\Magento\Catalog\Model\Category

Definition at line 108 of file View.php.

109  {
110  if (!$this->hasData('current_category')) {
111  $this->setData('current_category', $this->_coreRegistry->registry('current_category'));
112  }
113  return $this->getData('current_category');
114  }
getData($key='', $index=null)
Definition: DataObject.php:119
setData($key, $value=null)
Definition: DataObject.php:72

◆ getIdentities()

getIdentities ( )

Return identifiers for produced content

Returns
array

Implements IdentityInterface.

Definition at line 177 of file View.php.

178  {
179  return $this->getCurrentCategory()->getIdentities();
180  }

◆ getProductListHtml()

getProductListHtml ( )
Returns
string

Definition at line 98 of file View.php.

99  {
100  return $this->getChildHtml('product_list');
101  }

◆ isContentMode()

isContentMode ( )

Check if category display mode is "Static Block Only" For anchor category with applied filter Static Block Only mode not allowed

Returns
bool

Definition at line 156 of file View.php.

157  {
158  $category = $this->getCurrentCategory();
159  $res = false;
160  if ($category->getDisplayMode() == \Magento\Catalog\Model\Category::DM_PAGE) {
161  $res = true;
162  if ($category->getIsAnchor()) {
163  $state = $this->_catalogLayer->getState();
164  if ($state && $state->getFilters()) {
165  $res = false;
166  }
167  }
168  }
169  return $res;
170  }

◆ isMixedMode()

isMixedMode ( )

Check if category display mode is "Static Block and Products"

Returns
bool

Definition at line 145 of file View.php.

146  {
147  return $this->getCurrentCategory()->getDisplayMode() == \Magento\Catalog\Model\Category::DM_MIXED;
148  }

◆ isProductMode()

isProductMode ( )

Check if category display mode is "Products Only"

Returns
bool

Definition at line 136 of file View.php.

137  {
138  return $this->getCurrentCategory()->getDisplayMode() == \Magento\Catalog\Model\Category::DM_PRODUCT;
139  }

Field Documentation

◆ $_catalogLayer

$_catalogLayer
protected

Definition at line 28 of file View.php.

◆ $_categoryHelper

$_categoryHelper
protected

Definition at line 33 of file View.php.

◆ $_coreRegistry

$_coreRegistry = null
protected

Definition at line 21 of file View.php.


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