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

Public Member Functions

 __construct (\Magento\Framework\View\Element\Template\Context $context, \Magento\Framework\Url\EncoderInterface $urlEncoder, \Magento\Review\Helper\Data $reviewData, \Magento\Catalog\Api\ProductRepositoryInterface $productRepository, \Magento\Review\Model\RatingFactory $ratingFactory, \Magento\Framework\Message\ManagerInterface $messageManager, \Magento\Framework\App\Http\Context $httpContext, \Magento\Customer\Model\Url $customerUrl, array $data=[], \Magento\Framework\Serialize\Serializer\Json $serializer=null)
 
 getJsLayout ()
 
 getProductInfo ()
 
 getAction ()
 
 getRatings ()
 
 getRegisterUrl ()
 
- 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 ()
 
 getProductId ()
 
- 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

 $_reviewData = null
 
 $productRepository
 
 $_ratingFactory
 
 $urlEncoder
 
 $messageManager
 
 $httpContext
 
 $customerUrl
 
 $jsLayout
 
- 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

Review form block

@api

Author
Magento Core Team core@.nosp@m.mage.nosp@m.ntoco.nosp@m.mmer.nosp@m.ce.co.nosp@m.m @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Since
100.0.2

Definition at line 21 of file Form.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\View\Element\Template\Context  $context,
\Magento\Framework\Url\EncoderInterface  $urlEncoder,
\Magento\Review\Helper\Data  $reviewData,
\Magento\Catalog\Api\ProductRepositoryInterface  $productRepository,
\Magento\Review\Model\RatingFactory  $ratingFactory,
\Magento\Framework\Message\ManagerInterface  $messageManager,
\Magento\Framework\App\Http\Context  $httpContext,
\Magento\Customer\Model\Url  $customerUrl,
array  $data = [],
\Magento\Framework\Serialize\Serializer\Json  $serializer = null 
)

Form constructor.

Parameters
\Magento\Framework\View\Element\Template\Context$context
\Magento\Framework\Url\EncoderInterface$urlEncoder
\Magento\Review\Helper\Data$reviewData
\Magento\Catalog\Api\ProductRepositoryInterface$productRepository
\Magento\Review\Model\RatingFactory$ratingFactory
\Magento\Framework\Message\ManagerInterface$messageManager
\Magento\Framework\App\Http\Context$httpContext
Url$customerUrl
array$data
\Magento\Framework\Serialize\Serializer\Json | null$serializer
Exceptions

Definition at line 92 of file Form.php.

103  {
104  $this->urlEncoder = $urlEncoder;
105  $this->_reviewData = $reviewData;
106  $this->productRepository = $productRepository;
107  $this->_ratingFactory = $ratingFactory;
108  $this->messageManager = $messageManager;
109  $this->httpContext = $httpContext;
110  $this->customerUrl = $customerUrl;
111  parent::__construct($context, $data);
112  $this->jsLayout = isset($data['jsLayout']) ? $data['jsLayout'] : [];
114  ->get(\Magento\Framework\Serialize\Serializer\Json::class);
115  }

Member Function Documentation

◆ _construct()

_construct ( )
protected

Initialize review form

Returns
void

Definition at line 122 of file Form.php.

123  {
124  parent::_construct();
125 
126  $this->setAllowWriteReviewFlag(
127  $this->httpContext->getValue(Context::CONTEXT_AUTH)
128  || $this->_reviewData->getIsGuestAllowToWrite()
129  );
130  if (!$this->getAllowWriteReviewFlag()) {
131  $queryParam = $this->urlEncoder->encode(
132  $this->getUrl('*/*/*', ['_current' => true]) . '#review-form'
133  );
134  $this->setLoginLink(
135  $this->getUrl(
136  'customer/account/login/',
137  [Url::REFERER_QUERY_PARAM_NAME => $queryParam]
138  )
139  );
140  }
141 
142  $this->setTemplate('Magento_Review::form.phtml');
143  }
const REFERER_QUERY_PARAM_NAME
Definition: Url.php:32

◆ getAction()

getAction ( )

Get review product post action

Returns
string

Definition at line 173 of file Form.php.

174  {
175  return $this->getUrl(
176  'review/product/post',
177  [
178  '_secure' => $this->getRequest()->isSecure(),
179  'id' => $this->getProductId(),
180  ]
181  );
182  }

◆ getJsLayout()

getJsLayout ( )
Returns
string

Definition at line 148 of file Form.php.

149  {
150  return $this->serializer->serialize($this->jsLayout);
151  }

◆ getProductId()

getProductId ( )
protected

Get review product id

Returns
int

Definition at line 218 of file Form.php.

219  {
220  return $this->getRequest()->getParam('id', false);
221  }

◆ getProductInfo()

getProductInfo ( )

Get product info

Returns
\Magento\Catalog\Api\Data\ProductInterface
Exceptions

Definition at line 159 of file Form.php.

160  {
161  return $this->productRepository->getById(
162  $this->getProductId(),
163  false,
164  $this->_storeManager->getStore()->getId()
165  );
166  }

◆ getRatings()

getRatings ( )

Get collection of ratings

Returns
RatingCollection
Exceptions

Definition at line 190 of file Form.php.

191  {
192  return $this->_ratingFactory->create()->getResourceCollection()->addEntityFilter(
193  'product'
194  )->setPositionOrder()->addRatingPerStoreName(
195  $this->_storeManager->getStore()->getId()
196  )->setStoreFilter(
197  $this->_storeManager->getStore()->getId()
198  )->setActiveFilter(
199  true
200  )->load()->addOptionToItems();
201  }

◆ getRegisterUrl()

getRegisterUrl ( )

Return register URL

Returns
string

Definition at line 208 of file Form.php.

209  {
210  return $this->customerUrl->getRegisterUrl();
211  }

Field Documentation

◆ $_ratingFactory

$_ratingFactory
protected

Definition at line 42 of file Form.php.

◆ $_reviewData

$_reviewData = null
protected

Definition at line 28 of file Form.php.

◆ $customerUrl

$customerUrl
protected

Definition at line 64 of file Form.php.

◆ $httpContext

$httpContext
protected

Definition at line 59 of file Form.php.

◆ $jsLayout

$jsLayout
protected

Definition at line 69 of file Form.php.

◆ $messageManager

$messageManager
protected

Definition at line 54 of file Form.php.

◆ $productRepository

$productRepository
protected

Definition at line 35 of file Form.php.

◆ $urlEncoder

$urlEncoder
protected

Definition at line 47 of file Form.php.


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