Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
|
Public Member Functions | |
__construct (array $elements=null) | |
importElements (array $elements) | |
exportElements () | |
createElement ($elementId, array $data) | |
getElement ($elementId) | |
hasElement ($elementId) | |
unsetElement ($elementId, $recursive=true) | |
setAttribute ($elementId, $attribute, $value) | |
getAttribute ($elementId, $attribute) | |
renameElement ($oldId, $newId) | |
setAsChild ($elementId, $parentId, $alias='', $position=null) | |
unsetChild ($elementId, $alias=null) | |
reorderChild ($parentId, $childId, $position) | |
reorderToSibling ($parentId, $childId, $siblingId, $offset) | |
getChildId ($parentId, $alias) | |
getChildren ($parentId) | |
getParentId ($childId) | |
getChildAlias ($parentId, $childId) | |
addToParentGroup ($childId, $groupName) | |
getGroupChildNames ($parentId, $groupName) | |
Data Fields | |
const | PARENT = 'parent' |
const | CHILDREN = 'children' |
const | GROUPS = 'groups' |
Protected Member Functions | |
_assertParentRelation ($elementId) | |
_getChildOffset ($parentId, $childId) | |
_insertChild ($targetParentId, $elementId, $offset, $alias) | |
Protected Attributes | |
$_elements = [] | |
An associative data structure, that features "nested set" parent-child relations
Definition at line 14 of file Structure.php.
__construct | ( | array | $elements = null | ) |
Set elements in constructor
array | $elements |
Definition at line 35 of file Structure.php.
|
protected |
Verify relations of parent-child
string | $elementId |
LocalizedException |
Definition at line 87 of file Structure.php.
|
protected |
Calculate a relative offset of a child element in specified parent
string | $parentId | |
string | $childId |
LocalizedException | if specified elements have no parent-child relation |
Definition at line 548 of file Structure.php.
|
protected |
Insert an existing element as a child to existing element
The element must not be a child to any other element The target parent element must not have it as a child already
Offset – into which position to insert: 0 – set as 1st 1, 2 – after 1st, second, etc... -1, -2 – before last, before second last, etc... null – set as last
string | $targetParentId | |
string | $elementId | |
int | null | $offset | |
string | $alias |
LocalizedException |
Definition at line 600 of file Structure.php.
addToParentGroup | ( | $childId, | |
$groupName | |||
) |
Add element to parent group
string | $childId | |
string | $groupName |
Definition at line 505 of file Structure.php.
createElement | ( | $elementId, | |
array | $data | ||
) |
Create new element
string | $elementId | |
array | $data |
LocalizedException | if an element with this id already exists |
Definition at line 154 of file Structure.php.
exportElements | ( | ) |
getAttribute | ( | $elementId, | |
$attribute | |||
) |
Get element attribute
string | $elementId | |
string | $attribute |
Definition at line 248 of file Structure.php.
getChildAlias | ( | $parentId, | |
$childId | |||
) |
Get element alias by name
string | $parentId | |
string | $childId |
Definition at line 490 of file Structure.php.
getChildId | ( | $parentId, | |
$alias | |||
) |
Get child ID by parent ID and alias
string | $parentId | |
string | $alias |
Definition at line 451 of file Structure.php.
getChildren | ( | $parentId | ) |
Get all children
Returns in format 'id' => 'alias'
string | $parentId |
Definition at line 467 of file Structure.php.
getElement | ( | $elementId | ) |
Get existing element
string | $elementId |
Definition at line 173 of file Structure.php.
getGroupChildNames | ( | $parentId, | |
$groupName | |||
) |
Get element IDs for specified group
Note that it is expected behavior if a child has been moved out from this parent, but still remained in the group of old parent. The method will return only actual children. This is intentional, in case if the child returns back to the old parent.
string | $parentId | Name of an element containing group |
string | $groupName |
Definition at line 527 of file Structure.php.
getParentId | ( | $childId | ) |
Get name of parent element
string | $childId |
Definition at line 478 of file Structure.php.
hasElement | ( | $elementId | ) |
Whether specified element exists
string | $elementId |
Definition at line 184 of file Structure.php.
importElements | ( | array | $elements | ) |
Set elements from external source
array | $elements |
LocalizedException | if any format issues identified |
Definition at line 49 of file Structure.php.
renameElement | ( | $oldId, | |
$newId | |||
) |
Rename element ID
string | $oldId | |
string | $newId |
LocalizedException | if trying to overwrite another element |
Definition at line 265 of file Structure.php.
reorderChild | ( | $parentId, | |
$childId, | |||
$position | |||
) |
Reorder a child element relatively to specified position
Returns new position of the reordered element
string | $parentId | |
string | $childId | |
int | null | $position |
Definition at line 373 of file Structure.php.
reorderToSibling | ( | $parentId, | |
$childId, | |||
$siblingId, | |||
$offset | |||
) |
Reorder an element relatively to its sibling
$offset possible values: 1, 2 – set after the sibling towards end – by 1, by 2 positions, etc -1, -2 – set before the sibling towards start – by 1, by 2 positions, etc...
Both $childId and $siblingId must be children of the specified $parentId Returns new position of the reordered element
string | $parentId | |
string | $childId | |
string | $siblingId | |
int | $offset |
Definition at line 411 of file Structure.php.
setAsChild | ( | $elementId, | |
$parentId, | |||
$alias = '' , |
|||
$position = null |
|||
) |
Set element as a child to another element
string | $elementId | |
string | $parentId | |
string | $alias | |
int | null | $position |
LocalizedException | if attempting to set parent as child to its child (recursively) |
Definition at line 308 of file Structure.php.
setAttribute | ( | $elementId, | |
$attribute, | |||
$value | |||
) |
Set an arbitrary value to specified element attribute
string | $elementId | |
string | $attribute | |
mixed | $value |
Definition at line 226 of file Structure.php.
unsetChild | ( | $elementId, | |
$alias = null |
|||
) |
Unset element as a child of another element
Note that only parent-child relations will be deleted. Element itself will be retained. The method is polymorphic: 1 argument: element ID which is supposedly a child of some element 2 arguments: parent element ID and child alias
string | $elementId | ID of an element or its parent element |
string | null | $alias |
Definition at line 344 of file Structure.php.
unsetElement | ( | $elementId, | |
$recursive = true |
|||
) |
Remove element with specified ID from the structure
Can recursively delete all child elements. Returns false if there was no element found, therefore was nothing to delete.
string | $elementId | |
bool | $recursive |
Definition at line 199 of file Structure.php.
|
protected |
Definition at line 28 of file Structure.php.
const CHILDREN = 'children' |
Definition at line 21 of file Structure.php.
const GROUPS = 'groups' |
Definition at line 23 of file Structure.php.
const PARENT = 'parent' |
Reserved keys for storing structural relations
Definition at line 19 of file Structure.php.