Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
AbstractBlock Class Reference
Inheritance diagram for AbstractBlock:
DataObject BlockInterface AbstractBlock Container Gallery Category NewProducts Special Block Page DefaultRenderer AbstractOptions Render RendererPool FormKey Select RendererList Template Text BrokenAction BrokenConstructor BrokenLayout StubBlock Config Data Editable Newchild Rule Discounts Robots Config Container Link

Public Member Functions

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

Static Public Member Functions

static extractModuleName ($className)
 

Data Fields

const CACHE_GROUP = \Magento\Framework\App\Cache\Type\Block::TYPE_IDENTIFIER
 
const CACHE_KEY_PREFIX = 'BLOCK_'
 

Protected Member Functions

 _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

 $_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 Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Base class for all blocks.

Avoid inheriting from this class. Will be deprecated.

Marked as public API because it is actively used now.

@api @SuppressWarnings(PHPMD.ExcessivePublicCount) @SuppressWarnings(PHPMD.ExcessiveClassComplexity) @SuppressWarnings(PHPMD.CouplingBetweenObjects) @SuppressWarnings(PHPMD.TooManyFields) @SuppressWarnings(PHPMD.NumberOfChildren)

Since
100.0.2

Definition at line 25 of file AbstractBlock.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\View\Element\Context  $context,
array  $data = [] 
)

Constructor

Parameters
\Magento\Framework\View\Element\Context$context
array$data

Definition at line 185 of file AbstractBlock.php.

186  {
187  $this->_request = $context->getRequest();
188  $this->_layout = $context->getLayout();
189  $this->_eventManager = $context->getEventManager();
190  $this->_urlBuilder = $context->getUrlBuilder();
191  $this->_cache = $context->getCache();
192  $this->_design = $context->getDesignPackage();
193  $this->_session = $context->getSession();
194  $this->_sidResolver = $context->getSidResolver();
195  $this->_scopeConfig = $context->getScopeConfig();
196  $this->_assetRepo = $context->getAssetRepository();
197  $this->_viewConfig = $context->getViewConfig();
198  $this->_cacheState = $context->getCacheState();
199  $this->_logger = $context->getLogger();
200  $this->_escaper = $context->getEscaper();
201  $this->filterManager = $context->getFilterManager();
202  $this->_localeDate = $context->getLocaleDate();
203  $this->inlineTranslation = $context->getInlineTranslation();
204  if (isset($data['jsLayout'])) {
205  $this->jsLayout = $data['jsLayout'];
206  unset($data['jsLayout']);
207  }
208  parent::__construct($data);
209  $this->_construct();
210  }

Member Function Documentation

◆ _afterToHtml()

_afterToHtml (   $html)
protected

Processing block html after rendering

Parameters
string$html
Returns
string

Definition at line 698 of file AbstractBlock.php.

699  {
700  return $html;
701  }

◆ _beforeToHtml()

_beforeToHtml ( )
protected

Before rendering html, but after trying to load cache

Returns
$this

Definition at line 639 of file AbstractBlock.php.

640  {
641  return $this;
642  }

◆ _construct()

_construct ( )
protected

Internal constructor, that is called from real constructor

Please override this one instead of overriding real __construct constructor

Returns
void

Please override this one instead of overriding real __construct constructor

Definition at line 239 of file AbstractBlock.php.

240  {
244  }

◆ _getNotFoundUrl()

_getNotFoundUrl (   $route = '',
  $params = ['_direct' =,
'core/index/notFound']   
)
protected

Get 404 file not found url

Parameters
string$route
array$params
Returns
string

Definition at line 803 of file AbstractBlock.php.

804  {
805  return $this->getUrl($route, $params);
806  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ _getSidPlaceholder()

_getSidPlaceholder (   $cacheKey = null)
protected

Get SID placeholder for cache

Parameters
null | string$cacheKey
Returns
string

Definition at line 1134 of file AbstractBlock.php.

1135  {
1136  if ($cacheKey === null) {
1137  $cacheKey = $this->getCacheKey();
1138  }
1139 
1140  return '<!--SID=' . $cacheKey . '-->';
1141  }

◆ _loadCache()

_loadCache ( )
protected

Load block html from cache storage

Returns
string|false

Definition at line 1089 of file AbstractBlock.php.

1090  {
1091  if ($this->getCacheLifetime() === null || !$this->_cacheState->isEnabled(self::CACHE_GROUP)) {
1092  return false;
1093  }
1094  $cacheKey = $this->getCacheKey();
1095  $cacheData = $this->_cache->load($cacheKey);
1096  if ($cacheData) {
1097  $cacheData = str_replace(
1098  $this->_getSidPlaceholder($cacheKey),
1099  $this->_sidResolver->getSessionIdQueryParam($this->_session) . '=' . $this->_session->getSessionId(),
1100  $cacheData
1101  );
1102  }
1103  return $cacheData;
1104  }

◆ _prepareLayout()

_prepareLayout ( )
protected

Preparing global layout

You can redefine this method in child classes for changing layout

Returns
$this

Definition at line 284 of file AbstractBlock.php.

285  {
286  return $this;
287  }

◆ _saveCache()

_saveCache (   $data)
protected

Save block content to cache storage

Parameters
string$data
Returns
$this

Definition at line 1112 of file AbstractBlock.php.

1113  {
1114  if (!$this->getCacheLifetime() || !$this->_cacheState->isEnabled(self::CACHE_GROUP)) {
1115  return false;
1116  }
1117  $cacheKey = $this->getCacheKey();
1118  $data = str_replace(
1119  $this->_sidResolver->getSessionIdQueryParam($this->_session) . '=' . $this->_session->getSessionId(),
1120  $this->_getSidPlaceholder($cacheKey),
1121  $data
1122  );
1123 
1124  $this->_cache->save($data, $cacheKey, array_unique($this->getCacheTags()), $this->getCacheLifetime());
1125  return $this;
1126  }

◆ _toHtml()

_toHtml ( )
protected

Override this method in descendants to produce html

Returns
string

Definition at line 708 of file AbstractBlock.php.

709  {
710  return '';
711  }

◆ addChild()

addChild (   $alias,
  $block,
  $data = [] 
)

Create block with name: {parent}.{alias} and set as child

Parameters
string$alias
string$block
array$data
Returns
$this new block

Definition at line 385 of file AbstractBlock.php.

386  {
387  $block = $this->getLayout()->createBlock(
388  $block,
389  $this->getNameInLayout() . '.' . $alias,
390  ['data' => $data]
391  );
392  $this->setChild($alias, $block);
393  return $block;
394  }
$block
Definition: block.php:8
if(!trim($html)) $alias
Definition: details.phtml:20

◆ append()

append (   $element,
  $alias = '' 
)

Append element to the end of children list

Parameters
\Magento\Framework\View\Element\AbstractBlock | string$element
string$alias
Returns
$this

Definition at line 598 of file AbstractBlock.php.

599  {
600  return $this->insert($element, null, true, $alias);
601  }
if(!trim($html)) $alias
Definition: details.phtml:20
insert($element, $siblingName=0, $after=true, $alias='')
$element
Definition: element.phtml:12

◆ escapeCss()

escapeCss (   $string)

Escape string for the CSS context

Parameters
string$string
Returns
string
Since
101.0.0

Definition at line 927 of file AbstractBlock.php.

928  {
929  return $this->_escaper->escapeCss($string);
930  }

◆ escapeHtml()

escapeHtml (   $data,
  $allowedTags = null 
)

Escape HTML entities

Parameters
string | array$data
array | null$allowedTags
Returns
string

Definition at line 890 of file AbstractBlock.php.

891  {
892  return $this->_escaper->escapeHtml($data, $allowedTags);
893  }

◆ escapeHtmlAttr()

escapeHtmlAttr (   $string,
  $escapeSingleQuote = true 
)

Escape a string for the HTML attribute context

Parameters
string$string
boolean$escapeSingleQuote
Returns
string
Since
101.0.0

Definition at line 915 of file AbstractBlock.php.

916  {
917  return $this->_escaper->escapeHtmlAttr($string, $escapeSingleQuote);
918  }

◆ escapeJs()

escapeJs (   $string)

Escape string for the JavaScript context

Parameters
string$string
Returns
string
Since
101.0.0

Definition at line 902 of file AbstractBlock.php.

903  {
904  return $this->_escaper->escapeJs($string);
905  }

◆ escapeJsQuote()

escapeJsQuote (   $data,
  $quote = '\'' 
)

Escape quotes in java scripts

Parameters
string | array$data
string$quote
Returns
string|array
Deprecated:
101.0.0

Definition at line 994 of file AbstractBlock.php.

995  {
996  return $this->_escaper->escapeJsQuote($data, $quote);
997  }
$quote

◆ escapeQuote()

escapeQuote (   $data,
  $addSlashes = false 
)

Escape quotes inside html attributes

Use $addSlashes = false for escaping js that inside html attribute (onClick, onSubmit etc)

Parameters
string$data
bool$addSlashes
Returns
string
Deprecated:
101.0.0

Definition at line 981 of file AbstractBlock.php.

982  {
983  return $this->_escaper->escapeQuote($data, $addSlashes);
984  }

◆ escapeUrl()

escapeUrl (   $string)

Escape URL

Parameters
string$string
Returns
string

Definition at line 954 of file AbstractBlock.php.

955  {
956  return $this->_escaper->escapeUrl((string)$string);
957  }

◆ escapeXssInUrl()

escapeXssInUrl (   $data)

Escape xss in urls

Parameters
string$data
Returns
string
Deprecated:
101.0.0

Definition at line 966 of file AbstractBlock.php.

967  {
968  return $this->_escaper->escapeXssInUrl($data);
969  }

◆ extractModuleName()

static extractModuleName (   $className)
static

Extract module name from specified block class name

Parameters
string$className
Returns
string

Definition at line 873 of file AbstractBlock.php.

874  {
875  $namespace = substr(
876  $className,
877  0,
878  strpos($className, '\\' . 'Block')
879  );
880  return str_replace('\\', '_', $namespace);
881  }
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31

◆ formatDate()

formatDate (   $date = null,
  $format = \IntlDateFormatter::SHORT,
  $showTime = false,
  $timezone = null 
)

Retrieve formatting date

Parameters
null | string | \DateTimeInterface$date
int$format
bool$showTime
null | string$timezone
Returns
string

Definition at line 817 of file AbstractBlock.php.

822  {
823  $date = $date instanceof \DateTimeInterface ? $date : new \DateTime($date);
824  return $this->_localeDate->formatDateTime(
825  $date,
826  $format,
827  $showTime ? $format : \IntlDateFormatter::NONE,
828  null,
829  $timezone
830  );
831  }
$format
Definition: list.phtml:12

◆ formatTime()

formatTime (   $time = null,
  $format = \IntlDateFormatter::SHORT,
  $showDate = false 
)

Retrieve formatting time

Parameters
\DateTime | string | null$time
int$format
bool$showDate
Returns
string

Definition at line 841 of file AbstractBlock.php.

845  {
846  $time = $time instanceof \DateTimeInterface ? $time : new \DateTime($time);
847  return $this->_localeDate->formatDateTime(
848  $time,
849  $showDate ? $format : \IntlDateFormatter::NONE,
850  $format
851  );
852  }
$format
Definition: list.phtml:12

◆ getBlockHtml()

getBlockHtml (   $name)

Retrieve block html

Parameters
string$name
Returns
string

Definition at line 555 of file AbstractBlock.php.

556  {
557  $block = $this->_layout->getBlock($name);
558  if ($block) {
559  return $block->toHtml();
560  }
561  return '';
562  }
$block
Definition: block.php:8
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getCacheKey()

getCacheKey ( )

Get Key for caching block content

Returns
string

don't prevent recalculation by saving generated cache key because of ability to render single block instance with different data

Definition at line 1026 of file AbstractBlock.php.

1027  {
1028  if ($this->hasData('cache_key')) {
1029  return static::CACHE_KEY_PREFIX . $this->getData('cache_key');
1030  }
1031 
1036  $key = $this->getCacheKeyInfo();
1037 
1038  $key = array_values($key); // ignore array keys
1039 
1040  $key = implode('|', $key);
1041  $key = sha1($key); // use hashing to hide potentially private data
1042  return static::CACHE_KEY_PREFIX . $key;
1043  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getCacheKeyInfo()

getCacheKeyInfo ( )

Get cache key informative items

Provide string array key to share specific info item with FPC placeholder

Returns
string[]

Definition at line 1016 of file AbstractBlock.php.

1017  {
1018  return [$this->getNameInLayout()];
1019  }

◆ getCacheLifetime()

getCacheLifetime ( )
protected

Get block cache life time

Returns
int|bool|null

Definition at line 1070 of file AbstractBlock.php.

1071  {
1072  if (!$this->hasData('cache_lifetime')) {
1073  return null;
1074  }
1075 
1076  $cacheLifetime = $this->getData('cache_lifetime');
1077  if (false === $cacheLifetime || null === $cacheLifetime) {
1078  return null;
1079  }
1080 
1081  return (int)$cacheLifetime;
1082  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getCacheTags()

getCacheTags ( )
protected

Get tags array for saving cache

Returns
array

Definition at line 1050 of file AbstractBlock.php.

1051  {
1052  if (!$this->hasData('cache_tags')) {
1053  $tags = [];
1054  } else {
1055  $tags = $this->getData('cache_tags');
1056  }
1057  $tags[] = self::CACHE_GROUP;
1058 
1059  if ($this instanceof IdentityInterface) {
1060  $tags = array_merge($tags, $this->getIdentities());
1061  }
1062  return $tags;
1063  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getChildBlock()

getChildBlock (   $alias)

Retrieve child block by name

Parameters
string$alias
Returns
\Magento\Framework\View\Element\AbstractBlock|bool

Definition at line 477 of file AbstractBlock.php.

478  {
479  $layout = $this->getLayout();
480  if (!$layout) {
481  return false;
482  }
483  $name = $layout->getChildName($this->getNameInLayout(), $alias);
484  if ($name) {
485  return $layout->getBlock($name);
486  }
487  return false;
488  }
if(!trim($html)) $alias
Definition: details.phtml:20
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getChildChildHtml()

getChildChildHtml (   $alias,
  $childChildAlias = '',
  $useCache = true 
)

Render output of child child element

Parameters
string$alias
string$childChildAlias
bool$useCache
Returns
string

Definition at line 527 of file AbstractBlock.php.

528  {
529  $layout = $this->getLayout();
530  if (!$layout) {
531  return '';
532  }
533  $childName = $layout->getChildName($this->getNameInLayout(), $alias);
534  if (!$childName) {
535  return '';
536  }
537  $out = '';
538  if ($childChildAlias) {
539  $childChildName = $layout->getChildName($childName, $childChildAlias);
540  $out = $layout->renderElement($childChildName, $useCache);
541  } else {
542  foreach ($layout->getChildNames($childName) as $childChild) {
543  $out .= $layout->renderElement($childChild, $useCache);
544  }
545  }
546  return $out;
547  }
if(!trim($html)) $alias
Definition: details.phtml:20

◆ getChildData()

getChildData (   $alias,
  $key = '' 
)

Get a value from child block by specified key

Parameters
string$alias
string$key
Returns
mixed

Definition at line 625 of file AbstractBlock.php.

626  {
627  $child = $this->getChildBlock($alias);
628  if ($child) {
629  return $child->getData($key);
630  }
631  return null;
632  }
if(!trim($html)) $alias
Definition: details.phtml:20

◆ getChildHtml()

getChildHtml (   $alias = '',
  $useCache = true 
)

Retrieve child block HTML

Parameters
string$alias
boolean$useCache
Returns
string

Definition at line 497 of file AbstractBlock.php.

498  {
499  $layout = $this->getLayout();
500  if (!$layout) {
501  return '';
502  }
503  $name = $this->getNameInLayout();
504  $out = '';
505  if ($alias) {
506  $childName = $layout->getChildName($name, $alias);
507  if ($childName) {
508  $out = $layout->renderElement($childName, $useCache);
509  }
510  } else {
511  foreach ($layout->getChildNames($name) as $child) {
512  $out .= $layout->renderElement($child, $useCache);
513  }
514  }
515 
516  return $out;
517  }
if(!trim($html)) $alias
Definition: details.phtml:20
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getChildNames()

getChildNames ( )

Retrieves sorted list of child names

Returns
array

Definition at line 328 of file AbstractBlock.php.

329  {
330  $layout = $this->getLayout();
331  if (!$layout) {
332  return [];
333  }
334  return $layout->getChildNames($this->getNameInLayout());
335  }

◆ getGroupChildNames()

getGroupChildNames (   $groupName)

Get a group of child blocks

Returns an array of <alias> => <block> or an array of <alias> => <callback_result> The callback currently supports only $this methods and passes the alias as parameter

Parameters
string$groupName
Returns
array

Definition at line 613 of file AbstractBlock.php.

614  {
615  return $this->getLayout()->getGroupChildNames($this->getNameInLayout(), $groupName);
616  }

◆ getJsId()

getJsId (   $arg1 = null,
  $arg2 = null,
  $arg3 = null,
  $arg4 = null,
  $arg5 = null 
)

Generate id for using in JavaScript UI

Function takes an arbitrary amount of parameters

Parameters
string | null$arg1
string | null$arg2
string | null$arg3
string | null$arg4
string | null$arg5
Returns
string

Definition at line 744 of file AbstractBlock.php.

745  {
746  $args = [];
747  if ($arg1 !== null) {
748  $args[] = $arg1;
749  }
750  if ($arg2 !== null) {
751  $args[] = $arg2;
752  }
753  if ($arg3 !== null) {
754  $args[] = $arg3;
755  }
756  if ($arg4 !== null) {
757  $args[] = $arg4;
758  }
759  if ($arg5 !== null) {
760  $args[] = $arg5;
761  }
762  $rawId = $this->_nameInLayout . '-' . implode('-', $args);
763  return trim(preg_replace('/[^a-z0-9]+/', '-', strtolower($rawId)), '-');
764  }

◆ getJsLayout()

getJsLayout ( )

Retrieve serialized JS layout configuration ready to use in template

Returns
string

Definition at line 217 of file AbstractBlock.php.

218  {
219  return json_encode($this->jsLayout);
220  }

◆ getLayout()

getLayout ( )

Retrieve layout object

Returns
\Magento\Framework\View\LayoutInterface
Exceptions

Definition at line 295 of file AbstractBlock.php.

296  {
297  if (!$this->_layout) {
298  throw new \Magento\Framework\Exception\LocalizedException(
299  new \Magento\Framework\Phrase('Layout must be initialized')
300  );
301  }
302  return $this->_layout;
303  }

◆ getModuleName()

getModuleName ( )

Retrieve module name of block

Returns
string

Definition at line 859 of file AbstractBlock.php.

860  {
861  if (!$this->_getData('module_name')) {
862  $this->setData('module_name', self::extractModuleName(get_class($this)));
863  }
864  return $this->_getData('module_name');
865  }
setData($key, $value=null)
Definition: DataObject.php:72

◆ getNameInLayout()

getNameInLayout ( )

Get block name

Returns
string

Definition at line 1004 of file AbstractBlock.php.

◆ getParentBlock()

getParentBlock ( )

Retrieve parent block

Returns
\Magento\Framework\View\Element\AbstractBlock|bool

Definition at line 251 of file AbstractBlock.php.

252  {
253  $layout = $this->getLayout();
254  if (!$layout) {
255  return false;
256  }
257  $parentName = $layout->getParentName($this->getNameInLayout());
258  if ($parentName) {
259  return $layout->getBlock($parentName);
260  }
261  return false;
262  }

◆ getRequest()

getRequest ( )

Get request

Returns
\Magento\Framework\App\RequestInterface

Definition at line 227 of file AbstractBlock.php.

◆ getUiId()

getUiId (   $arg1 = null,
  $arg2 = null,
  $arg3 = null,
  $arg4 = null,
  $arg5 = null 
)

Retrieve data-ui-id attribute

Retrieve data-ui-id attribute which will distinguish link/input/container/anything else in template among others. Function takes an arbitrary amount of parameters.

Parameters
string | null$arg1
string | null$arg2
string | null$arg3
string | null$arg4
string | null$arg5
Returns
string

Definition at line 727 of file AbstractBlock.php.

728  {
729  return ' data-ui-id="' . $this->getJsId($arg1, $arg2, $arg3, $arg4, $arg5) . '" ';
730  }
getJsId($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)

◆ getUrl()

getUrl (   $route = '',
  $params = [] 
)

Generate url by route and parameters

Parameters
string$route
array$params
Returns
string

Definition at line 773 of file AbstractBlock.php.

774  {
775  return $this->_urlBuilder->getUrl($route, $params);
776  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getVar()

getVar (   $name,
  $module = null 
)

Get variable value from view configuration

Module name can be omitted. If omitted, it will be determined automatically.

Parameters
string$namevariable name
string | null$moduleoptional module name
Returns
string|false

Definition at line 1152 of file AbstractBlock.php.

1153  {
1154  $module = $module ?: $this->getModuleName();
1155  return $this->_viewConfig->getViewConfig()->getVarValue($module, $name);
1156  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getViewFileUrl()

getViewFileUrl (   $fileId,
array  $params = [] 
)

Retrieve url of a view file

Parameters
string$fileId
array$params
Returns
string

Definition at line 785 of file AbstractBlock.php.

786  {
787  try {
788  $params = array_merge(['_secure' => $this->getRequest()->isSecure()], $params);
789  return $this->_assetRepo->getUrlWithParams($fileId, $params);
790  } catch (\Magento\Framework\Exception\LocalizedException $e) {
791  $this->_logger->critical($e);
792  return $this->_getNotFoundUrl();
793  }
794  }
_getNotFoundUrl($route='', $params=['_direct'=> 'core/index/notFound'])
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ insert()

insert (   $element,
  $siblingName = 0,
  $after = true,
  $alias = '' 
)

Insert child element into specified position

By default inserts as first element into children list

Parameters
\Magento\Framework\View\Element\AbstractBlock | string$element
string | int | null$siblingName
bool$after
string$alias
Returns
$this|bool

Definition at line 575 of file AbstractBlock.php.

576  {
577  $layout = $this->getLayout();
578  if (!$layout) {
579  return false;
580  }
581  if ($element instanceof \Magento\Framework\View\Element\AbstractBlock) {
582  $elementName = $element->getNameInLayout();
583  } else {
585  }
586  $layout->setChild($this->_nameInLayout, $elementName, $alias);
587  $layout->reorderChild($this->_nameInLayout, $elementName, $siblingName, $after);
588  return $this;
589  }
if(!trim($html)) $alias
Definition: details.phtml:20
$elementName
Definition: gallery.phtml:10
$element
Definition: element.phtml:12

◆ isScopePrivate()

isScopePrivate ( )

Determine if the block scope is private or public.

Returns true if scope is private, false otherwise

Returns
bool

Definition at line 1165 of file AbstractBlock.php.

◆ setAttribute()

setAttribute (   $name,
  $value = null 
)

Set block attribute value

Wrapper for method "setData"

Parameters
string$name
mixed$value
Returns
$this

Definition at line 346 of file AbstractBlock.php.

347  {
348  return $this->setData($name, $value);
349  }
$value
Definition: gender.phtml:16
setData($key, $value=null)
Definition: DataObject.php:72
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setChild()

setChild (   $alias,
  $block 
)

Set child block

Parameters
string$alias
\Magento\Framework\View\Element\AbstractBlock | string$block
Returns
$this

Definition at line 358 of file AbstractBlock.php.

359  {
360  $layout = $this->getLayout();
361  if (!$layout) {
362  return $this;
363  }
364  $thisName = $this->getNameInLayout();
365  if ($layout->getChildName($thisName, $alias)) {
366  $this->unsetChild($alias);
367  }
368  if ($block instanceof self) {
369  $block = $block->getNameInLayout();
370  }
371 
372  $layout->setChild($thisName, $block, $alias);
373 
374  return $this;
375  }
$block
Definition: block.php:8
if(!trim($html)) $alias
Definition: details.phtml:20

◆ setLayout()

setLayout ( \Magento\Framework\View\LayoutInterface  $layout)

Set layout object

Parameters
\Magento\Framework\View\LayoutInterface$layout
Returns
$this

Definition at line 270 of file AbstractBlock.php.

271  {
272  $this->_layout = $layout;
273  $this->_prepareLayout();
274  return $this;
275  }

◆ setNameInLayout()

setNameInLayout (   $name)

Sets/changes name of a block in layout

Parameters
string$name
Returns
$this

Definition at line 311 of file AbstractBlock.php.

312  {
313  if (!empty($this->_nameInLayout) && $this->_layout) {
314  if ($name === $this->_nameInLayout) {
315  return $this;
316  }
317  $this->_layout->renameElement($this->_nameInLayout, $name);
318  }
319  $this->_nameInLayout = $name;
320  return $this;
321  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ stripTags()

stripTags (   $data,
  $allowableTags = null,
  $allowHtmlEntities = false 
)

Wrapper for standard strip_tags() function with extra functionality for html entities

Parameters
string$data
string | null$allowableTags
bool$allowHtmlEntities
Returns
string

Definition at line 940 of file AbstractBlock.php.

941  {
942  return $this->filterManager->stripTags(
943  $data,
944  ['allowableTags' => $allowableTags, 'escape' => $allowHtmlEntities]
945  );
946  }

◆ unsetCallChild()

unsetCallChild (   $alias,
  $callback,
  $result,
  $params 
)

Call a child and unset it, if callback matched result

Variable $params will pass to child callback $params may be array, if called from layout with elements with same name, for example: ...<foo>value_1</foo><foo>value_2</foo><foo>value_3</foo>

Or, if called like this: ...<foo>value_1</foo><bar>value_2</bar><baz>value_3</baz>

  • then it will be $params1, $params2, $params3

It is no difference anyway, because they will be transformed in appropriate way.

Parameters
string$alias
string$callback
mixed$result
array$params
Returns
$this

Definition at line 431 of file AbstractBlock.php.

432  {
433  $child = $this->getChildBlock($alias);
434  if ($child) {
435  $args = func_get_args();
436  $alias = array_shift($args);
437  $callback = array_shift($args);
438  $result = (string)array_shift($args);
439  if (!is_array($params)) {
440  $params = $args;
441  }
442 
443  // @codingStandardsIgnoreStart
444  if ($result == call_user_func_array([&$child, $callback], $params)) {
445  $this->unsetChild($alias);
446  }
447  // @codingStandardsIgnoreEnd
448  }
449  return $this;
450  }
if(!trim($html)) $alias
Definition: details.phtml:20
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ unsetChild()

unsetChild (   $alias)

Unset child block

Parameters
string$alias
Returns
$this

Definition at line 402 of file AbstractBlock.php.

403  {
404  $layout = $this->getLayout();
405  if (!$layout) {
406  return $this;
407  }
408  $layout->unsetChild($this->getNameInLayout(), $alias);
409  return $this;
410  }
if(!trim($html)) $alias
Definition: details.phtml:20

◆ unsetChildren()

unsetChildren ( )

Unset all children blocks

Returns
$this

Definition at line 457 of file AbstractBlock.php.

458  {
459  $layout = $this->getLayout();
460  if (!$layout) {
461  return $this;
462  }
463  $name = $this->getNameInLayout();
464  $children = $layout->getChildNames($name);
465  foreach ($children as $childName) {
466  $layout->unsetChild($name, $childName);
467  }
468  return $this;
469  }
$children
Definition: actions.phtml:11
if(!isset($_GET['name'])) $name
Definition: log.php:14

Field Documentation

◆ $_assetRepo

$_assetRepo
protected

Definition at line 113 of file AbstractBlock.php.

◆ $_cache

$_cache
protected

Definition at line 177 of file AbstractBlock.php.

◆ $_cacheState

$_cacheState
protected

Definition at line 127 of file AbstractBlock.php.

◆ $_design

$_design
protected

Definition at line 42 of file AbstractBlock.php.

◆ $_escaper

$_escaper
protected

Definition at line 141 of file AbstractBlock.php.

◆ $_eventManager

$_eventManager
protected

Definition at line 99 of file AbstractBlock.php.

◆ $_frontController

$_frontController
protected

Definition at line 106 of file AbstractBlock.php.

◆ $_isScopePrivate

$_isScopePrivate = false
protected

Definition at line 166 of file AbstractBlock.php.

◆ $_layout

$_layout
protected

Definition at line 70 of file AbstractBlock.php.

◆ $_localeDate

$_localeDate
protected

Definition at line 153 of file AbstractBlock.php.

◆ $_logger

$_logger
protected

Definition at line 134 of file AbstractBlock.php.

◆ $_nameInLayout

$_nameInLayout
protected

Definition at line 63 of file AbstractBlock.php.

◆ $_request

$_request
protected

Definition at line 84 of file AbstractBlock.php.

◆ $_scopeConfig

$_scopeConfig
protected

Definition at line 171 of file AbstractBlock.php.

◆ $_session

$_session
protected

Definition at line 49 of file AbstractBlock.php.

◆ $_sidResolver

$_sidResolver
protected

Definition at line 56 of file AbstractBlock.php.

◆ $_urlBuilder

$_urlBuilder
protected

Definition at line 91 of file AbstractBlock.php.

◆ $_viewConfig

$_viewConfig
protected

Definition at line 120 of file AbstractBlock.php.

◆ $filterManager

$filterManager
protected

Definition at line 148 of file AbstractBlock.php.

◆ $inlineTranslation

$inlineTranslation
protected

Definition at line 158 of file AbstractBlock.php.

◆ $jsLayout

$jsLayout = []
protected

Definition at line 77 of file AbstractBlock.php.

◆ CACHE_GROUP

Cache group Tag

Definition at line 30 of file AbstractBlock.php.

◆ CACHE_KEY_PREFIX

const CACHE_KEY_PREFIX = 'BLOCK_'

Prefix for cache key of block

Definition at line 35 of file AbstractBlock.php.


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