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

Public Member Functions

 __construct (\Magento\Backend\Block\Template\Context $context, \Magento\Catalog\Model\Product\Type $productType, array $data=[], Json $serializer=null)
 
 render (AbstractElement $element)
 
 setElement (AbstractElement $element)
 
 getElement ()
 
 getCategoriesChooserUrl ()
 
 getProductsChooserUrl ()
 
 getBlockChooserUrl ()
 
 getTemplateChooserUrl ()
 
 getDisplayOnSelectHtml ()
 
 getDisplayOnContainers ()
 
 getLayoutsChooser ()
 
 getPageLayoutsPageChooser ()
 
 getAddLayoutButtonHtml ()
 
 getRemoveLayoutButtonHtml ()
 
 getPageGroups ()
 
- Public Member Functions inherited from Template
 __construct (\Magento\Backend\Block\Template\Context $context, array $data=[])
 
 getFormKey ()
 
 isOutputEnabled ($moduleName=null)
 
 getAuthorization ()
 
 getToolbar ()
 
- 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 ()
 
- Public Member Functions inherited from RendererInterface
 render (\Magento\Framework\Data\Form\Element\AbstractElement $element)
 

Protected Member Functions

 _getDisplayOnOptions ()
 
- Protected Member Functions inherited from Template
 _toHtml ()
 
- 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

 $_element = null
 
 $_template = 'Magento_Widget::instance/edit/layout.phtml'
 
 $_productType
 
- Protected Attributes inherited from Template
 $_authorization
 
 $mathRandom
 
 $_backendSession
 
 $formKey
 
 $nameBuilder
 
- 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

Widget Instance page groups (predefined layouts group) to display on

@method \Magento\Widget\Model\Widget\Instance getWidgetInstance()

Definition at line 20 of file Layout.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Backend\Block\Template\Context  $context,
\Magento\Catalog\Model\Product\Type  $productType,
array  $data = [],
Json  $serializer = null 
)
Parameters
\Magento\Backend\Block\Template\Context$context
\Magento\Catalog\Model\Product\Type$productType
array$data
Json | null$serializer

Definition at line 48 of file Layout.php.

53  {
54  $this->_productType = $productType;
55  $this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
56  parent::__construct($context, $data);
57  }

Member Function Documentation

◆ _getDisplayOnOptions()

_getDisplayOnOptions ( )
protected

Retrieve Display On options array.

  • Categories (anchor and not anchor)
  • Products (product types depend on configuration)
  • Generic (predefined) pages (all pages and single layout update)
Returns
array

Definition at line 164 of file Layout.php.

165  {
166  $options = [];
167  $options[] = ['value' => '', 'label' => $this->escapeHtmlAttr(__('-- Please Select --'))];
168  $options[] = [
169  'label' => __('Categories'),
170  'value' => [
171  ['value' => 'anchor_categories', 'label' => $this->escapeHtmlAttr(__('Anchor Categories'))],
172  ['value' => 'notanchor_categories', 'label' => $this->escapeHtmlAttr(__('Non-Anchor Categories'))],
173  ],
174  ];
175  foreach ($this->_productType->getTypes() as $typeId => $type) {
176  $productsOptions[] = [
177  'value' => $typeId . '_products',
178  'label' => $this->escapeHtmlAttr($type['label']),
179  ];
180  }
181  array_unshift(
182  $productsOptions,
183  ['value' => 'all_products', 'label' => $this->escapeHtmlAttr(__('All Product Types'))]
184  );
185  $options[] = ['label' => $this->escapeHtmlAttr(__('Products')), 'value' => $productsOptions];
186  $options[] = [
187  'label' => $this->escapeHtmlAttr(__('Generic Pages')),
188  'value' => [
189  ['value' => 'all_pages', 'label' => $this->escapeHtmlAttr(__('All Pages'))],
190  ['value' => 'pages', 'label' => $this->escapeHtmlAttr(__('Specified Page'))],
191  ['value' => 'page_layouts', 'label' => $this->escapeHtmlAttr(__('Page Layouts'))],
192  ],
193  ];
194  return $options;
195  }
__()
Definition: __.php:13
$type
Definition: item.phtml:13
escapeHtmlAttr($string, $escapeSingleQuote=true)

◆ getAddLayoutButtonHtml()

getAddLayoutButtonHtml ( )

Retrieve add layout button html

Returns
string

Definition at line 304 of file Layout.php.

305  {
306  $button = $this->getLayout()->createBlock(
307  \Magento\Backend\Block\Widget\Button::class
308  )->setData(
309  [
310  'label' => __('Add Layout Update'),
311  'onclick' => 'WidgetInstance.addPageGroup({})',
312  'class' => 'action-add',
313  ]
314  );
315  return $button->toHtml();
316  }
__()
Definition: __.php:13

◆ getBlockChooserUrl()

getBlockChooserUrl ( )

Generate url to get reference block chooser by ajax query

Returns
string

Definition at line 118 of file Layout.php.

119  {
120  return $this->getUrl('adminhtml/*/blocks', ['_current' => true]);
121  }

◆ getCategoriesChooserUrl()

getCategoriesChooserUrl ( )

Generate url to get categories chooser by ajax query

Returns
string

Definition at line 98 of file Layout.php.

99  {
100  return $this->getUrl('adminhtml/*/categories', ['_current' => true]);
101  }

◆ getDisplayOnContainers()

getDisplayOnContainers ( )

Generate array of parameters for every container type to create html template

Returns
array @SuppressWarnings(PHPMD.UnusedLocalVariable)

Definition at line 203 of file Layout.php.

204  {
205  $container = [];
206  $container['anchor'] = [
207  'label' => 'Categories',
208  'code' => 'categories',
209  'name' => 'anchor_categories',
210  'layout_handle' => \Magento\Widget\Model\Widget\Instance::ANCHOR_CATEGORY_LAYOUT_HANDLE,
211  'is_anchor_only' => 1,
212  'product_type_id' => '',
213  ];
214  $container['notanchor'] = [
215  'label' => 'Categories',
216  'code' => 'categories',
217  'name' => 'notanchor_categories',
218  'layout_handle' => \Magento\Widget\Model\Widget\Instance::NOTANCHOR_CATEGORY_LAYOUT_HANDLE,
219  'is_anchor_only' => 0,
220  'product_type_id' => '',
221  ];
222  $container['all_products'] = [
223  'label' => 'Products',
224  'code' => 'products',
225  'name' => 'all_products',
226  'layout_handle' => \Magento\Widget\Model\Widget\Instance::PRODUCT_LAYOUT_HANDLE,
227  'is_anchor_only' => '',
228  'product_type_id' => '',
229  ];
230  foreach ($this->_productType->getTypes() as $typeId => $type) {
231  $container[$typeId] = [
232  'label' => 'Products',
233  'code' => 'products',
234  'name' => $typeId . '_products',
235  'layout_handle' => str_replace(
236  '{{TYPE}}',
237  $typeId,
238  \Magento\Widget\Model\Widget\Instance::PRODUCT_TYPE_LAYOUT_HANDLE
239  ),
240  'is_anchor_only' => '',
241  'product_type_id' => $typeId,
242  ];
243  }
244  return $container;
245  }
$type
Definition: item.phtml:13

◆ getDisplayOnSelectHtml()

getDisplayOnSelectHtml ( )

Create and return html of select box Display On

Returns
string

Definition at line 138 of file Layout.php.

139  {
140  $selectBlock = $this->getLayout()->createBlock(
141  \Magento\Framework\View\Element\Html\Select::class
142  )->setName(
143  'widget_instance[<%- data.id %>][page_group]'
144  )->setId(
145  'widget_instance[<%- data.id %>][page_group]'
146  )->setClass(
147  'required-entry page_group_select select'
148  )->setExtraParams(
149  "onchange=\"WidgetInstance.displayPageGroup(this.value+\'_<%- data.id %>\')\""
150  )->setOptions(
151  $this->_getDisplayOnOptions()
152  );
153  return $selectBlock->toHtml();
154  }

◆ getElement()

getElement ( )

Getter

Returns
AbstractElement

Definition at line 88 of file Layout.php.

◆ getLayoutsChooser()

getLayoutsChooser ( )

Retrieve layout select chooser html

Returns
string

Definition at line 252 of file Layout.php.

253  {
254  $chooserBlock = $this->getLayout()->createBlock(
255  \Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Chooser\Layout::class
256  )->setName(
257  'widget_instance[<%- data.id %>][pages][layout_handle]'
258  )->setId(
259  'layout_handle'
260  )->setClass(
261  'required-entry select'
262  )->setExtraParams(
263  "onchange=\"WidgetInstance.loadSelectBoxByType(\'block_reference\', " .
264  "this.up(\'div.pages\'), this.value)\""
265  )->setArea(
266  $this->getWidgetInstance()->getArea()
267  )->setTheme(
268  $this->getWidgetInstance()->getThemeId()
269  );
270  return $chooserBlock->toHtml();
271  }

◆ getPageGroups()

getPageGroups ( )

Prepare and retrieve page groups data of widget instance

Returns
array

Definition at line 342 of file Layout.php.

343  {
344  $widgetInstance = $this->getWidgetInstance();
345  $pageGroups = [];
346  if ($widgetInstance->getPageGroups()) {
347  foreach ($widgetInstance->getPageGroups() as $pageGroup) {
348  $pageGroups[] = $this->serializer->serialize($this->getPageGroup($pageGroup));
349  }
350  }
351  return $pageGroups;
352  }

◆ getPageLayoutsPageChooser()

getPageLayoutsPageChooser ( )

Retrieve layout select chooser html

Returns
string

Definition at line 278 of file Layout.php.

279  {
280  $chooserBlock = $this->getLayout()->createBlock(
281  \Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Chooser\DesignAbstraction::class
282  )->setName(
283  'widget_instance[<%- data.id %>][page_layouts][layout_handle]'
284  )->setId(
285  'layout_handle'
286  )->setClass(
287  'required-entry select'
288  )->setExtraParams(
289  "onchange=\"WidgetInstance.loadSelectBoxByType(\'block_reference\', " .
290  "this.up(\'div.pages\'), this.value)\""
291  )->setArea(
292  $this->getWidgetInstance()->getArea()
293  )->setTheme(
294  $this->getWidgetInstance()->getThemeId()
295  );
296  return $chooserBlock->toHtml();
297  }

◆ getProductsChooserUrl()

getProductsChooserUrl ( )

Generate url to get products chooser by ajax query

Returns
string

Definition at line 108 of file Layout.php.

109  {
110  return $this->getUrl('adminhtml/*/products', ['_current' => true]);
111  }

◆ getRemoveLayoutButtonHtml()

getRemoveLayoutButtonHtml ( )

Retrieve remove layout button html

Returns
string

Definition at line 323 of file Layout.php.

324  {
325  $button = $this->getLayout()->createBlock(
326  \Magento\Backend\Block\Widget\Button::class
327  )->setData(
328  [
329  'label' => $this->escapeHtmlAttr(__('Remove Layout Update')),
330  'onclick' => 'WidgetInstance.removePageGroup(this)',
331  'class' => 'action-delete',
332  ]
333  );
334  return $button->toHtml();
335  }
__()
Definition: __.php:13
escapeHtmlAttr($string, $escapeSingleQuote=true)

◆ getTemplateChooserUrl()

getTemplateChooserUrl ( )

Generate url to get template chooser by ajax query

Returns
string

Definition at line 128 of file Layout.php.

129  {
130  return $this->getUrl('adminhtml/*/template', ['_current' => true]);
131  }

◆ render()

render ( AbstractElement  $element)

Render given element (return html of element)

Parameters
AbstractElement$element
Returns
string

Definition at line 65 of file Layout.php.

66  {
67  $this->setElement($element);
68  return $this->toHtml();
69  }
$element
Definition: element.phtml:12

◆ setElement()

setElement ( AbstractElement  $element)

Setter

Parameters
AbstractElement$element
Returns
$this

Definition at line 77 of file Layout.php.

78  {
79  $this->_element = $element;
80  return $this;
81  }
$element
Definition: element.phtml:12

Field Documentation

◆ $_element

$_element = null
protected

Definition at line 25 of file Layout.php.

◆ $_productType

$_productType
protected

Definition at line 35 of file Layout.php.

◆ $_template

$_template = 'Magento_Widget::instance/edit/layout.phtml'
protected

Definition at line 30 of file Layout.php.


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