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

Public Member Functions

 __construct (\Magento\Framework\View\Element\Template\Context $context, \Magento\Directory\Helper\Data $directoryHelper, \Magento\Framework\Json\EncoderInterface $jsonEncoder, \Magento\Framework\App\Cache\Type\Config $configCacheType, \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollectionFactory, \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollectionFactory, array $data=[])
 
 getLoadrRegionUrl ()
 
 getCountryCollection ()
 
 getCountryHtmlSelect ($defValue=null, $name='country_id', $id='country', $title='Country')
 
 getRegionCollection ()
 
 getRegionHtmlSelect ()
 
 getCountryId ()
 
 getRegionsJs ()
 
- 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

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

 $_configCacheType
 
 $_regionCollectionFactory
 
 $_countryCollectionFactory
 
 $_jsonEncoder
 
 $directoryHelper
 
- 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

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 11 of file Data.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\View\Element\Template\Context  $context,
\Magento\Directory\Helper\Data  $directoryHelper,
\Magento\Framework\Json\EncoderInterface  $jsonEncoder,
\Magento\Framework\App\Cache\Type\Config  $configCacheType,
\Magento\Directory\Model\ResourceModel\Region\CollectionFactory  $regionCollectionFactory,
\Magento\Directory\Model\ResourceModel\Country\CollectionFactory  $countryCollectionFactory,
array  $data = [] 
)
Parameters
\Magento\Framework\View\Element\Template\Context$context
\Magento\Directory\Helper\Data$directoryHelper
\Magento\Framework\Json\EncoderInterface$jsonEncoder
\Magento\Framework\App\Cache\Type\Config$configCacheType
\Magento\Directory\Model\ResourceModel\Region\CollectionFactory$regionCollectionFactory
\Magento\Directory\Model\ResourceModel\Country\CollectionFactory$countryCollectionFactory
array$data

Definition at line 52 of file Data.php.

60  {
61  parent::__construct($context, $data);
62  $this->directoryHelper = $directoryHelper;
63  $this->_jsonEncoder = $jsonEncoder;
64  $this->_configCacheType = $configCacheType;
65  $this->_regionCollectionFactory = $regionCollectionFactory;
66  $this->_countryCollectionFactory = $countryCollectionFactory;
67  }

Member Function Documentation

◆ getCountryCollection()

getCountryCollection ( )
Returns
\Magento\Directory\Model\ResourceModel\Country\Collection

Definition at line 80 of file Data.php.

81  {
82  $collection = $this->getData('country_collection');
83  if ($collection === null) {
84  $collection = $this->_countryCollectionFactory->create()->loadByStore();
85  $this->setData('country_collection', $collection);
86  }
87 
88  return $collection;
89  }
getData($key='', $index=null)
Definition: DataObject.php:119
setData($key, $value=null)
Definition: DataObject.php:72

◆ getCountryHtmlSelect()

getCountryHtmlSelect (   $defValue = null,
  $name = 'country_id',
  $id = 'country',
  $title = 'Country' 
)
Parameters
null | string$defValue
string$name
string$id
string$title
Returns
string

Definition at line 112 of file Data.php.

113  {
114  \Magento\Framework\Profiler::start('TEST: ' . __METHOD__, ['group' => 'TEST', 'method' => __METHOD__]);
115  if ($defValue === null) {
116  $defValue = $this->getCountryId();
117  }
118  $cacheKey = 'DIRECTORY_COUNTRY_SELECT_STORE_' . $this->_storeManager->getStore()->getCode();
119  $cache = $this->_configCacheType->load($cacheKey);
120  if ($cache) {
121  $options = $this->getSerializer()->unserialize($cache);
122  } else {
123  $options = $this->getCountryCollection()
124  ->setForegroundCountries($this->getTopDestinations())
125  ->toOptionArray();
126  $this->_configCacheType->save($this->getSerializer()->serialize($options), $cacheKey);
127  }
128  $html = $this->getLayout()->createBlock(
129  \Magento\Framework\View\Element\Html\Select::class
130  )->setName(
131  $name
132  )->setId(
133  $id
134  )->setTitle(
135  __($title)
136  )->setValue(
137  $defValue
138  )->setOptions(
139  $options
140  )->setExtraParams(
141  'data-validate="{\'validate-select\':true}"'
142  )->getHtml();
143 
144  \Magento\Framework\Profiler::stop('TEST: ' . __METHOD__);
145  return $html;
146  }
$title
Definition: default.phtml:14
$id
Definition: fieldset.phtml:14
__()
Definition: __.php:13
serialize($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
Definition: DataObject.php:446
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getCountryId()

getCountryId ( )
Returns
string

Definition at line 198 of file Data.php.

199  {
200  $countryId = $this->getData('country_id');
201  if ($countryId === null) {
202  $countryId = $this->directoryHelper->getDefaultCountry();
203  }
204  return $countryId;
205  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getLoadrRegionUrl()

getLoadrRegionUrl ( )
Returns
string

Definition at line 72 of file Data.php.

73  {
74  return $this->getUrl('directory/json/childRegion');
75  }

◆ getRegionCollection()

getRegionCollection ( )
Returns
\Magento\Directory\Model\ResourceModel\Region\Collection

Definition at line 151 of file Data.php.

152  {
153  $collection = $this->getData('region_collection');
154  if ($collection === null) {
155  $collection = $this->_regionCollectionFactory->create()->addCountryFilter($this->getCountryId())->load();
156 
157  $this->setData('region_collection', $collection);
158  }
159  return $collection;
160  }
getData($key='', $index=null)
Definition: DataObject.php:119
setData($key, $value=null)
Definition: DataObject.php:72

◆ getRegionHtmlSelect()

getRegionHtmlSelect ( )
Returns
string

Definition at line 165 of file Data.php.

166  {
167  \Magento\Framework\Profiler::start('TEST: ' . __METHOD__, ['group' => 'TEST', 'method' => __METHOD__]);
168  $cacheKey = 'DIRECTORY_REGION_SELECT_STORE' . $this->_storeManager->getStore()->getId();
169  $cache = $this->_configCacheType->load($cacheKey);
170  if ($cache) {
171  $options = $this->getSerializer()->unserialize($cache);
172  } else {
173  $options = $this->getRegionCollection()->toOptionArray();
174  $this->_configCacheType->save($this->getSerializer()->serialize($options), $cacheKey);
175  }
176  $html = $this->getLayout()->createBlock(
177  \Magento\Framework\View\Element\Html\Select::class
178  )->setName(
179  'region'
180  )->setTitle(
181  __('State/Province')
182  )->setId(
183  'state'
184  )->setClass(
185  'required-entry validate-state'
186  )->setValue(
187  intval($this->getRegionId())
188  )->setOptions(
189  $options
190  )->getHtml();
191  \Magento\Framework\Profiler::start('TEST: ' . __METHOD__, ['group' => 'TEST', 'method' => __METHOD__]);
192  return $html;
193  }
__()
Definition: __.php:13
serialize($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
Definition: DataObject.php:446

◆ getRegionsJs()

getRegionsJs ( )
Returns
string

Definition at line 210 of file Data.php.

211  {
212  \Magento\Framework\Profiler::start('TEST: ' . __METHOD__, ['group' => 'TEST', 'method' => __METHOD__]);
213  $regionsJs = $this->getData('regions_js');
214  if (!$regionsJs) {
215  $countryIds = [];
216  foreach ($this->getCountryCollection() as $country) {
217  $countryIds[] = $country->getCountryId();
218  }
219  $collection = $this->_regionCollectionFactory->create()->addCountryFilter($countryIds)->load();
220  $regions = [];
221  foreach ($collection as $region) {
222  if (!$region->getRegionId()) {
223  continue;
224  }
225  $regions[$region->getCountryId()][$region->getRegionId()] = [
226  'code' => $region->getCode(),
227  'name' => $region->getName(),
228  ];
229  }
230  $regionsJs = $this->_jsonEncoder->encode($regions);
231  }
232  \Magento\Framework\Profiler::stop('TEST: ' . __METHOD__);
233  return $regionsJs;
234  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getTopDestinations()

getTopDestinations ( )
protected

Retrieve list of top destinations countries

Returns
array

Definition at line 96 of file Data.php.

97  {
98  $destinations = (string)$this->_scopeConfig->getValue(
99  'general/country/destinations',
100  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
101  );
102  return !empty($destinations) ? explode(',', $destinations) : [];
103  }

Field Documentation

◆ $_configCacheType

$_configCacheType
protected

Definition at line 16 of file Data.php.

◆ $_countryCollectionFactory

$_countryCollectionFactory
protected

Definition at line 26 of file Data.php.

◆ $_jsonEncoder

$_jsonEncoder
protected

Definition at line 31 of file Data.php.

◆ $_regionCollectionFactory

$_regionCollectionFactory
protected

Definition at line 21 of file Data.php.

◆ $directoryHelper

$directoryHelper
protected

Definition at line 36 of file Data.php.


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