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

Public Member Functions

 __construct (\Magento\Framework\View\Element\Template\Context $context, \Magento\Sales\Model\ResourceModel\Order\Invoice\Comment\CollectionFactory $invoiceCollectionFactory, \Magento\Sales\Model\ResourceModel\Order\Creditmemo\Comment\CollectionFactory $memoCollectionFactory, \Magento\Sales\Model\ResourceModel\Order\Shipment\Comment\CollectionFactory $shipmentCollectionFactory, array $data=[])
 
 setEntity ($entity)
 
 getEntity ()
 
 getComments ()
 
 hasComments ()
 
- 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 Attributes

 $_invoiceCollectionFactory
 
 $_memoCollectionFactory
 
 $_shipmentCollectionFactory
 
 $_entity
 
 $_commentCollection
 
- 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_'
 
- 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)
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

@api

Since
100.0.2

Definition at line 12 of file Comments.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\View\Element\Template\Context  $context,
\Magento\Sales\Model\ResourceModel\Order\Invoice\Comment\CollectionFactory  $invoiceCollectionFactory,
\Magento\Sales\Model\ResourceModel\Order\Creditmemo\Comment\CollectionFactory  $memoCollectionFactory,
\Magento\Sales\Model\ResourceModel\Order\Shipment\Comment\CollectionFactory  $shipmentCollectionFactory,
array  $data = [] 
)
Parameters
\Magento\Framework\View\Element\Template\Context$context
\Magento\Sales\Model\ResourceModel\Order\Invoice\Comment\CollectionFactory$invoiceCollectionFactory
\Magento\Sales\Model\ResourceModel\Order\Creditmemo\Comment\CollectionFactory$memoCollectionFactory
\Magento\Sales\Model\ResourceModel\Order\Shipment\Comment\CollectionFactory$shipmentCollectionFactory
array$data

Definition at line 50 of file Comments.php.

56  {
57  parent::__construct($context, $data);
58  $this->_invoiceCollectionFactory = $invoiceCollectionFactory;
59  $this->_memoCollectionFactory = $memoCollectionFactory;
60  $this->_shipmentCollectionFactory = $shipmentCollectionFactory;
61  }

Member Function Documentation

◆ getComments()

getComments ( )

Initialize model comments and return comment collection

Returns
\Magento\Sales\Model\ResourceModel\Order\Comment\Collection\AbstractCollection
Exceptions

Definition at line 93 of file Comments.php.

94  {
95  if ($this->_commentCollection === null) {
96  $entity = $this->getEntity();
97  if ($entity instanceof \Magento\Sales\Model\Order\Invoice) {
98  $this->_commentCollection = $this->_invoiceCollectionFactory->create();
99  } elseif ($entity instanceof \Magento\Sales\Model\Order\Creditmemo) {
100  $this->_commentCollection = $this->_memoCollectionFactory->create();
101  } elseif ($entity instanceof \Magento\Sales\Model\Order\Shipment) {
102  $this->_commentCollection = $this->_shipmentCollectionFactory->create();
103  } else {
104  throw new \Magento\Framework\Exception\LocalizedException(__('We found an invalid entity model.'));
105  }
106 
107  $this->_commentCollection->setParentFilter($entity)->setCreatedAtOrder()->addVisibleOnFrontFilter();
108  }
109 
111  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13
$entity
Definition: element.phtml:22

◆ getEntity()

getEntity ( )

Gets comments parent model instance

Returns
\Magento\Sales\Model\AbstractModel

Definition at line 82 of file Comments.php.

83  {
84  return $this->_entity;
85  }

◆ hasComments()

hasComments ( )

Returns whether there are comments to show on frontend

Returns
bool

Definition at line 118 of file Comments.php.

119  {
120  return $this->getComments()->count() > 0;
121  }

◆ setEntity()

setEntity (   $entity)

Sets comments parent model instance

Parameters
\Magento\Sales\Model\AbstractModel$entity
Returns
$this

Definition at line 69 of file Comments.php.

70  {
71  $this->_entity = $entity;
72  $this->_commentCollection = null;
73  // Changing model and resource model can lead to change of comment collection
74  return $this;
75  }
$entity
Definition: element.phtml:22

Field Documentation

◆ $_commentCollection

$_commentCollection
protected

Definition at line 41 of file Comments.php.

◆ $_entity

$_entity
protected

Definition at line 34 of file Comments.php.

◆ $_invoiceCollectionFactory

$_invoiceCollectionFactory
protected

Definition at line 17 of file Comments.php.

◆ $_memoCollectionFactory

$_memoCollectionFactory
protected

Definition at line 22 of file Comments.php.

◆ $_shipmentCollectionFactory

$_shipmentCollectionFactory
protected

Definition at line 27 of file Comments.php.


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