Download the PHP package pragmatic-modules/jslayout-parser without Composer
On this page you can find all versions of the php package pragmatic-modules/jslayout-parser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pragmatic-modules/jslayout-parser
More information about pragmatic-modules/jslayout-parser
Files in pragmatic-modules/jslayout-parser
Package jslayout-parser
Short Description Lightweight PHP library that was created to make work with `$jsLayout` in Magento 2 less spaghetti, and more object-oriented.
License MIT
Homepage https://rusin.work
Informations about the package jslayout-parser
JS Layout Parser
Lightweight standalone PHP library that was created to make work with $jsLayout
in Magento 2 less spaghetti, and more object-oriented.
Installation
Usage On Checkout
Add new layout processor by implementing LayoutProcessorInterface
, and inject it into layoutProcessors
array.
File: etc/frontend/di.xml
Inject Pragmatic\JsLayoutParser\Model\JsLayoutParser
into processor and parse $jsLayout
for selected root component.
You can find a list of available component methods below.
JsLayoutParser Methods
parse( array $jsLayout, string $rootComponent )
Parse $jsLayout
into nested component objects tree.
$rootComponent
is name of the component out of $jsLayout['components']
that will be used as a base path for any operations.
Returns root Component
object.
Component Methods
- asArray( )
- getComponentName( )
- getParent( )
- remove( )
- hasChild( string $componentName )
- getChild( string $componentName )
- addChild( ComponentInterface $component )
- removeChild ( string $componentName )
- hasNestedChild ( string $path, string $childSeparator = '.' )
- getNestedChild ( string $componentName, string $childSeparator = '.' )
- moveNestedChild ( string $sourcePath, string $destinationPath, string $childSeparator = '.' )
- removeNestedChild ( string $path, string string $childSeparator = '.' )
- hasChildren ( )
- getChildren ( )
- isChildOf ( ComponentInterface $component )
- getComponent ( )
- setComponent ( string $component )
- getConfig ( )
- setConfig ( array $config, bool $replace = false )
- getDataScope ( )
- setDataScope ( string $dataScope )
- getDisplayArea ( )
- setDisplayArea ( string $displayArea )
- getLabel ( )
- setLabel ( $label )
- getProvider ( )
- setProvider ( string $provider )
- getSortOrder ( )
- setSortOrder ( string $sortOrder )
- getValidation ( )
- setValidation ( array $validation )
- getFilterBy ( )
- setFilterBy ( ?array $filterBy )
- isVisible ( )
- setIsVisible ( bool $visible )
- isRequired ( )
- setIsRequired ( bool $required )
asArray( )
Recursively converts component object and all of its nested children into a plain array that can be returned through $jsLayout
.
Example:
scroll up️
getComponentName( )
Get component name in layout.
Returns string.
Example:
jsLayout equivalent:
In associative $jsLayout
array components are stored as nested key-value pairs, where value are arrays with nested
children. It is not possible to determine parent's key within child scope. The same array might be used in multiple
places within jsLayout, so recursive searching is not an option.
In other words, you must know the name before retrieving component:
and once you get into child scope, there is no way to dynamically tell what's the parent key:
The closest you can get to the parser behaviour is by doing:
scroll up️
getParent( )
Get parent component.
Returns ComponentInterface
if parent exists.
Returns NULL if parent does not exist.
Example:
jsLayout equivalent:
scroll up️
remove( )
Remove component with all descendants from the component tree.
This method has no return value.
Example:
jsLayout equivalent:
scroll up️
hasChild ( string $componentName )
Check if component has a child with a given name.
Returns bool.
Example:
jsLayout equivalent:
scroll up️
getChild( string $componentName )
Get component child.
Returns ComponentInterface
if child exists.
Returns NULL if child does not exist.
Example:
jsLayout equivalent:
scroll up️
addChild( ComponentInterface $component )
Add new component as a child of the current component object.
This method throws Exception
if component with the same name is already a child of current component.
Returns self on success.
Example:
jsLayout equivalent:
scroll up️
removeChild ( string $componentName )
Remove child from the component.
This method throws Exception
if child does not exist within component.
This method has no return value.
Example:
jsLayout equivalent:
scroll up️
hasNestedChild ( string $path, string $childSeparator = '.' )
Check if component has a nested child with a given path.
By default, children are separated by a dot. This behaviour can be adjusted by passing custom separator as a second argument.
Returns bool.
Example:
jsLayout equivalent:
scroll up️
getNestedChild ( string $componentName, string $childSeparator = '.' )
Get component nested child.
By default, children are separated by a dot. This behaviour can be adjusted by passing custom separator as a second argument.
Returns ComponentInterface
if nested child exists.
Returns NULL if nested child does not exist.
Example:
jsLayout equivalent:
scroll up️
moveNestedChild ( string $sourcePath, string $destinationPath, string $childSeparator = '.' )
Move nested child from source to destination.
By default, children are separated by a dot. This behaviour can be adjusted by passing custom separator as a third argument.
This method throws Exception
if source or destination does not exist.
This method has no return value.
Example:
jsLayout equivalent:
scroll up️
removeNestedChild ( string $path, string string $childSeparator = '.' )
Remove nested child by path.
By default, children are separated by a dot. This behaviour can be adjusted by passing custom separator as a third argument.
This method throws Exception
if source or destination does not exist.
This method has no return value.
Example:
jsLayout equivalent:
scroll up️
hasChildren ( )
Check if component has children.
Returns true if at least one child exists, returns false otherwise.
Example:
jsLayout equivalent:
scroll up️
getChildren ( )
Get component children.
Returns array of components.
Returns empty array if component has no children.
Example:
jsLayout equivalent:
scroll up️
isChildOf ( ComponentInterface $component )
Check if component is child of given component.
Example:
jsLayout equivalent:
In associative $jsLayout
array components are stored as nested key-value pairs, where value are arrays with nested
children. It is not possible to determine parent within child scope.
scroll up️
getComponent ( )
Get UI Component of given component object.
Example:
jsLayout equivalent:
scroll up️
setComponent ( string $component )
Set UI Component of given component object.
Example:
jsLayout equivalent:
scroll up️
getConfig ( )
Get component configuration.
Returns array.
Example:
jsLayout equivalent:
scroll up️
setConfig ( array $config, bool $replace = false )
Set component configuration.
Configurations are merged together by default. Previous values remain intact except the ones that have the same keys as $config
array.
$config
values have higher priority and can be used to replace parts of existing configuration.
Entire component configuration can be overwritten by $config
by using $replace = true
.
Returns self.
Example:
jsLayout equivalent:
scroll up️
getDataScope ( )
Get component data scope.
Returns string or null.
Example:
jsLayout equivalent:
scroll up️
setDataScope ( string $dataScope )
Set component data scope.
Returns self.
Example:
jsLayout equivalent:
scroll up️
getDisplayArea ( )
Get component display area.
Returns string or null.
Example:
jsLayout equivalent:
scroll up️
setDisplayArea ( string $displayArea )
Set component display area.
Returns self.
Example:
jsLayout equivalent:
scroll up️
getLabel ( )
Get component label.
Returns string, Magento\Framework\Phrase
, or null.
Example:
jsLayout equivalent:
scroll up️
setLabel ( $label )
Set component label.
$label
should be either string, Magento\Framework\Phrase
, or null.
Returns self.
Example:
jsLayout equivalent:
scroll up️
getProvider ( )
Get component provider.
Returns string or null.
Example:
jsLayout equivalent:
scroll up️
setProvider ( string $provider )
Set component provider.
Returns self.
Example:
jsLayout equivalent:
scroll up️
getSortOrder ( )
Get component sort order.
Returns string, or null.
Example:
jsLayout equivalent:
scroll up️
setSortOrder ( string $sortOrder )
Set component sort order.
Returns self.
Example:
jsLayout equivalent:
scroll up️
getValidation ( )
Get component validation rules.
Returns array or null.
Example:
jsLayout equivalent:
scroll up️
setValidation ( array $validation )
Set component validation rules.
Returns self.
Example:
jsLayout equivalent:
scroll up️
getFilterBy ( )
Get component filter by configuration.
Returns array or null.
Example:
jsLayout equivalent:
scroll up️
setFilterBy ( ?array $filterBy )
Set component filter by configuration.
Returns self.
Example:
jsLayout equivalent:
scroll up️
isVisible ( )
Get component visibility.
Returns bool.
Example:
jsLayout equivalent:
scroll up️
setIsVisible ( bool $visible )
Set component visibility.
Returns self.
Example:
jsLayout equivalent:
scroll up️
isRequired ( )
Get component required
flag.
Returns bool.
Example:
jsLayout equivalent:
scroll up️
setIsRequired ( bool $required )
Set component required
flag.
Returns self.
Example:
jsLayout equivalent:
scroll up️