Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Container Class Reference
Inheritance diagram for Container:
GeneratorInterface

Public Member Functions

 getType ()
 
 process (Layout\Reader\Context $readerContext, Layout\Generator\Context $generatorContext)
 
 generateContainer (Layout\Data\Structure $structure, $elementName, $options)
 
- Public Member Functions inherited from GeneratorInterface
 process (Reader\Context $readerContext, Generator\Context $generatorContext)
 

Data Fields

const CONTAINER_OPT_HTML_TAG = 'htmlTag'
 
const CONTAINER_OPT_HTML_CLASS = 'htmlClass'
 
const CONTAINER_OPT_HTML_ID = 'htmlId'
 
const CONTAINER_OPT_LABEL = 'label'
 
const TYPE = 'container'
 

Protected Member Functions

 validateOptions ($options)
 

Protected Attributes

 $allowedTags
 

Detailed Description

Definition at line 10 of file Container.php.

Member Function Documentation

◆ generateContainer()

generateContainer ( Layout\Data\Structure  $structure,
  $elementName,
  $options 
)

Set container-specific data to structure element

Parameters
\Magento\Framework\View\Layout\Data\Structure$structure
string$elementName
array$options
Returns
void

Definition at line 83 of file Container.php.

87  {
88  unset($options['type']);
89 
90  $this->validateOptions($options);
91 
92  foreach ($options as $key => $value) {
93  $structure->setAttribute($elementName, $key, $value);
94  }
95  }
$value
Definition: gender.phtml:16
$elementName
Definition: gallery.phtml:10

◆ getType()

getType ( )

{Return type of generator

Returns
string
}

Returns
string

Implements GeneratorInterface.

Definition at line 49 of file Container.php.

◆ process()

process ( Layout\Reader\Context  $readerContext,
Layout\Generator\Context  $generatorContext 
)

Process container elements

Parameters
\Magento\Framework\View\Layout\Reader\Context$readerContext
Context$generatorContext
Returns
$this

Definition at line 61 of file Container.php.

62  {
63  $structure = $generatorContext->getStructure();
64  $scheduledStructure = $readerContext->getScheduledStructure();
65  foreach ($scheduledStructure->getElements() as $elementName => $element) {
66  list($type, $data) = $element;
67  if ($type === self::TYPE) {
68  $this->generateContainer($structure, $elementName, $data['attributes']);
69  $scheduledStructure->unsetElement($elementName);
70  }
71  }
72  return $this;
73  }
$type
Definition: item.phtml:13
generateContainer(Layout\Data\Structure $structure, $elementName, $options)
Definition: Container.php:83
$elementName
Definition: gallery.phtml:10
$element
Definition: element.phtml:12

◆ validateOptions()

validateOptions (   $options)
protected
Parameters
array$options
Returns
void
Exceptions

Definition at line 102 of file Container.php.

103  {
104  if (!empty($options[Layout\Element::CONTAINER_OPT_HTML_TAG])
105  && !in_array(
107  $this->allowedTags
108  )
109  ) {
110  throw new \Magento\Framework\Exception\LocalizedException(
111  new \Magento\Framework\Phrase(
112  'Html tag "%1" is forbidden for usage in containers. Consider to use one of the allowed: %2.',
113  [$options[Layout\Element::CONTAINER_OPT_HTML_TAG], implode(', ', $this->allowedTags)]
114  )
115  );
116  }
117 
118  if (empty($options[Layout\Element::CONTAINER_OPT_HTML_TAG])
119  && (
122  )
123  ) {
124  throw new \Magento\Framework\Exception\LocalizedException(
125  new \Magento\Framework\Phrase('HTML ID or class will not have effect, if HTML tag is not specified.')
126  );
127  }
128  }

Field Documentation

◆ $allowedTags

$allowedTags
protected
Initial value:
= [
'aside',
'dd',
'div',
'dl',
'fieldset',
'main',
'nav',
'header',
'footer',
'ol',
'p',
'section',
'table',
'tfoot',
'ul',
]

Definition at line 26 of file Container.php.

◆ CONTAINER_OPT_HTML_CLASS

const CONTAINER_OPT_HTML_CLASS = 'htmlClass'

Definition at line 16 of file Container.php.

◆ CONTAINER_OPT_HTML_ID

const CONTAINER_OPT_HTML_ID = 'htmlId'

Definition at line 17 of file Container.php.

◆ CONTAINER_OPT_HTML_TAG

const CONTAINER_OPT_HTML_TAG = 'htmlTag'

#+ Names of container options in layout

Definition at line 15 of file Container.php.

◆ CONTAINER_OPT_LABEL

const CONTAINER_OPT_LABEL = 'label'

Definition at line 18 of file Container.php.

◆ TYPE

const TYPE = 'container'

#-

Definition at line 21 of file Container.php.


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