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

Public Member Functions

 __construct (\Psr\Log\LoggerInterface $logger, State $state, array $elements=null)
 
 createStructuralElement ($name, $type, $class)
 
 reorderChildElement ($parentName, $childName, $offsetOrSibling, $after=true)
 

Protected Member Functions

 _generateAnonymousName ($class)
 
 _filterSearchMinus ($needle, array $haystack, $isLast)
 

Protected Attributes

 $_nameIncrement = []
 
 $logger
 
 $state
 

Detailed Description

An associative data structure, that features "nested set" parent-child relations

@api

Since
100.0.2

Definition at line 17 of file Structure.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Psr\Log\LoggerInterface  $logger,
State  $state,
array  $elements = null 
)

Constructor

Parameters
\Psr\Log\LoggerInterface$logger
State$state
array$elements

Definition at line 43 of file Structure.php.

47  {
48  $this->logger = $logger;
49  $this->state = $state;
50  parent::__construct($elements);
51  }

Member Function Documentation

◆ _filterSearchMinus()

_filterSearchMinus (   $needle,
array  $haystack,
  $isLast 
)
protected

Search for an array element using needle, but needle may be '-', which means "first" or "last" element

Returns first or last element in the haystack, or the $needle argument

Parameters
string$needle
array$haystack
bool$isLast
Returns
string

Definition at line 147 of file Structure.php.

148  {
149  if ('-' === $needle) {
150  if ($isLast) {
151  return array_pop($haystack);
152  }
153  return array_shift($haystack);
154  }
155  return $needle;
156  }

◆ _generateAnonymousName()

_generateAnonymousName (   $class)
protected

Generate anonymous element name for structure

Parameters
string$class
Returns
string

Definition at line 78 of file Structure.php.

79  {
80  $position = strpos($class, '\\Block\\');
81  $key = $position !== false ? substr($class, $position + 7) : $class;
82  $key = strtolower(trim($key, '_'));
83 
84  if (!isset($this->_nameIncrement[$key])) {
85  $this->_nameIncrement[$key] = 0;
86  }
87 
88  do {
89  $name = $key . '_' . $this->_nameIncrement[$key]++;
90  } while ($this->hasElement($name));
91 
92  return $name;
93  }
$_option $_optionId $class
Definition: date.phtml:13
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ createStructuralElement()

createStructuralElement (   $name,
  $type,
  $class 
)

Register an element in structure

Will assign an "anonymous" name to the element, if provided with an empty name

Parameters
string$name
string$type
string$class
Returns
string

Definition at line 63 of file Structure.php.

64  {
65  if (empty($name)) {
67  }
68  $this->createElement($name, ['type' => $type]);
69  return $name;
70  }
$type
Definition: item.phtml:13
$_option $_optionId $class
Definition: date.phtml:13
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ reorderChildElement()

reorderChildElement (   $parentName,
  $childName,
  $offsetOrSibling,
  $after = true 
)

Reorder a child of a specified element

If $offsetOrSibling is null, it will put the element to the end If $offsetOrSibling is numeric (integer) value, it will put the element after/before specified position Otherwise – after/before specified sibling

Parameters
string$parentName
string$childName
string | int | null$offsetOrSibling
bool$after
Returns
void

Definition at line 108 of file Structure.php.

109  {
110  if (is_numeric($offsetOrSibling)) {
111  $offset = (int)abs($offsetOrSibling) * ($after ? 1 : -1);
112  $this->reorderChild($parentName, $childName, $offset);
113  } elseif (null === $offsetOrSibling) {
114  $this->reorderChild($parentName, $childName, null);
115  } else {
116  $children = array_keys($this->getChildren($parentName));
117  if ($this->getChildId($parentName, $offsetOrSibling) !== false) {
118  $offsetOrSibling = $this->getChildId($parentName, $offsetOrSibling);
119  }
120  $sibling = $this->_filterSearchMinus($offsetOrSibling, $children, $after);
121  if ($childName !== $sibling) {
122  $siblingParentName = $this->getParentId($sibling);
123  if ($parentName !== $siblingParentName) {
124  if ($this->state->getMode() === State::MODE_DEVELOPER) {
125  $this->logger->info(
126  "Broken reference: the '{$childName}' tries to reorder itself towards '{$sibling}', but " .
127  "their parents are different: '{$parentName}' and '{$siblingParentName}' respectively."
128  );
129  }
130  return;
131  }
132  $this->reorderToSibling($parentName, $childName, $sibling, $after ? 1 : -1);
133  }
134  }
135  }
_filterSearchMinus($needle, array $haystack, $isLast)
Definition: Structure.php:147
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
reorderChild($parentName, $childName, $offsetOrSibling, $after=true)
Definition: Layout.php:410
$children
Definition: actions.phtml:11

Field Documentation

◆ $_nameIncrement

$_nameIncrement = []
protected

Definition at line 24 of file Structure.php.

◆ $logger

$logger
protected

Definition at line 29 of file Structure.php.

◆ $state

$state
protected

Definition at line 34 of file Structure.php.


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