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

Public Member Functions

 __construct (ObjectManagerInterface $objectManager, ManagerInterface $componentManager, InterpreterInterface $argumentInterpreter, ContextFactory $contextFactory, array $data=[], array $componentChildFactories=[], DataInterface $definitionData=null, DataInterfaceFactory $configFactory=null)
 
- 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)
 

Protected Member Functions

 createChildComponent (array &$bundleComponents, ContextInterface $renderContext, $identifier, array $arguments=[])
 
 argumentsResolver ($identifier, array $componentData)
 
 getBundleChildren (array $children=[])
 
 mergeMetadata ($identifier, array $bundleComponents, $reverseMerge=false)
 
 mergeMetadataElement (array $bundleComponents, $name, array $data, $reverseMerge=false)
 
 mergeMetadataItem (array $bundleComponents, array $metadata, $reverseMerge=false)
 
 getDataProvider ($identifier, array $bundleComponents)
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $objectManager
 
 $argumentInterpreter
 
 $contextFactory
 
 $componentManager
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Class UiComponentFactory

@api @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Since
100.0.2

Definition at line 29 of file UiComponentFactory.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ObjectManagerInterface  $objectManager,
ManagerInterface  $componentManager,
InterpreterInterface  $argumentInterpreter,
ContextFactory  $contextFactory,
array  $data = [],
array  $componentChildFactories = [],
DataInterface  $definitionData = null,
DataInterfaceFactory  $configFactory = null 
)
Parameters
ObjectManagerInterface$objectManager
ManagerInterface$componentManager
InterpreterInterface$argumentInterpreter
ContextFactory$contextFactory
DataInterfaceFactory | null$configFactory
array$data
array$componentChildFactories
DataInterface | null$definitionData

Definition at line 83 of file UiComponentFactory.php.

92  {
93  $this->objectManager = $objectManager;
94  $this->componentManager = $componentManager;
95  $this->argumentInterpreter = $argumentInterpreter;
96  $this->contextFactory = $contextFactory;
97  $this->componentChildFactories = $componentChildFactories;
98  $this->configFactory = $configFactory ?: $this->objectManager->get(DataInterfaceFactory::class);
99  parent::__construct($data);
100  $this->definitionData = $definitionData ?:
101  $this->objectManager->get(DataInterface::class);
102  }
$configFactory
Definition: config_data.php:43

Member Function Documentation

◆ argumentsResolver()

argumentsResolver (   $identifier,
array  $componentData 
)
protected

Resolve arguments

Parameters
string$identifier
array$componentData
Returns
array

Definition at line 174 of file UiComponentFactory.php.

175  {
177  $className = $attributes['class'];
178  unset($attributes['class']);
180 
181  if (!isset($arguments['data'])) {
182  $arguments['data'] = [];
183  }
184 
185  unset($attributes['component']);
186  $arguments['data'] = array_merge($arguments['data'], ['name' => $identifier], $attributes);
187  return [$className, $arguments];
188  }
$attributes
Definition: matrix.phtml:13
$arguments
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31

◆ createChildComponent()

createChildComponent ( array &  $bundleComponents,
ContextInterface  $renderContext,
  $identifier,
array  $arguments = [] 
)
protected

Create child components

Parameters
array$bundleComponents
ContextInterface$renderContext
string$identifier
array$arguments
Returns
UiComponentInterface

Add an ability to fill component variables from child factory.

Factory return nothing because factory should put created components in the right place

Prevent passing ACL restricted blocks to htmlContent constructor

Definition at line 113 of file UiComponentFactory.php.

118  {
119  $componentArguments = &$bundleComponents['arguments'];
120  list($className, $componentArguments) = $this->argumentsResolver($identifier, $bundleComponents);
121  if (isset($componentArguments['data']['disabled']) && (int)$componentArguments['data']['disabled']) {
122  return null;
123  }
124 
128  $bundleComponents['components'] = [];
129  $components = &$bundleComponents['components'];
130 
131  if (isset($this->componentChildFactories[$className])) {
132  $factory = $this->componentChildFactories[$className];
133 
138  $factory->create($bundleComponents, $arguments);
139  } else {
140  foreach ($bundleComponents['children'] as $childrenIdentifier => $childrenData) {
142  $childrenData,
143  $renderContext,
144  $childrenIdentifier,
145  $arguments
146  );
147  $components[$childrenIdentifier] = $children;
148  }
149  }
150  $components = array_filter($components);
151  $componentArguments['components'] = $components;
152 
156  if (isset($componentArguments['block']) && !$componentArguments['block']) {
157  return null;
158  }
159 
160  if (!isset($componentArguments['context'])) {
161  $componentArguments['context'] = $renderContext;
162  }
163 
164  return $this->objectManager->create($className, $componentArguments);
165  }
$arguments
$children
Definition: actions.phtml:11
createChildComponent(array &$bundleComponents, ContextInterface $renderContext, $identifier, array $arguments=[])
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31
argumentsResolver($identifier, array $componentData)

◆ getBundleChildren()

getBundleChildren ( array  $children = [])
protected

Get bundle children

Parameters
array$children
Returns
array
Exceptions
LocalizedException
Since
100.1.0

Definition at line 263 of file UiComponentFactory.php.

264  {
265  $bundleChildren = [];
266 
267  foreach ($children as $identifier => $config) {
268  if (!isset($config['componentType'])) {
269  throw new LocalizedException(new Phrase(
270  'The "componentType" configuration parameter is required for the "%1" component.',
271  $identifier
272  ));
273  }
274 
275  if (!isset($componentArguments['context'])) {
276  throw new LocalizedException(
277  new \Magento\Framework\Phrase(
278  'An error occurred with the UI component. Each component needs context. Verify and try again.'
279  )
280  );
281  }
282 
283  $rawComponentData = $this->definitionData->get($config['componentType']);
284  list(, $componentArguments) = $this->argumentsResolver($identifier, $rawComponentData);
285  $arguments = array_replace_recursive($componentArguments, ['data' => ['config' => $config]]);
287 
288  $bundleChildren[$identifier] = $rawComponentData;
289  $bundleChildren[$identifier]['children'] = [];
290 
291  if (isset($arguments['data']['config']['children'])) {
292  $bundleChildren[$identifier]['children'] = $this->getBundleChildren(
293  $arguments['data']['config']['children']
294  );
295  }
296  }
297 
298  return $bundleChildren;
299  }
$config
Definition: fraud_order.php:17
$arguments
$children
Definition: actions.phtml:11
argumentsResolver($identifier, array $componentData)

◆ getDataProvider()

getDataProvider (   $identifier,
array  $bundleComponents 
)
protected

Find and return data provider

Parameters
string$identifier
array$bundleComponents
Returns
DataProviderInterface|null
Since
100.1.0

Definition at line 426 of file UiComponentFactory.php.

427  {
428  foreach ($bundleComponents[$identifier]['children'] as $childrenData) {
429  if (isset($childrenData['arguments']['dataProvider'])
430  && $childrenData['arguments']['dataProvider'] instanceof DataProviderInterface
431  ) {
432  return $childrenData['arguments']['dataProvider'];
433  }
434  }
435 
436  return null;
437  }

◆ mergeMetadata()

mergeMetadata (   $identifier,
array  $bundleComponents,
  $reverseMerge = false 
)
protected

Merge data provider's metadata to components

Parameters
string$identifier
array$bundleComponents
bool$reverseMerge
Returns
array
Since
100.1.0

Definition at line 310 of file UiComponentFactory.php.

311  {
312  $dataProvider = $this->getDataProvider($identifier, $bundleComponents);
313  if ($dataProvider instanceof DataProviderInterface) {
314  $metadata = [
315  $identifier => [
316  'children' => $dataProvider->getMeta(),
317  ],
318  ];
319  $bundleComponents = $this->mergeMetadataItem($bundleComponents, $metadata, $reverseMerge);
320  }
321 
322  return $bundleComponents;
323  }
getDataProvider($identifier, array $bundleComponents)
mergeMetadataItem(array $bundleComponents, array $metadata, $reverseMerge=false)

◆ mergeMetadataElement()

mergeMetadataElement ( array  $bundleComponents,
  $name,
array  $data,
  $reverseMerge = false 
)
protected

Find element in components or its containers and merge data to it

Parameters
array$bundleComponents
string$name
array$data
bool$reverseMerge
Returns
array
Since
100.1.0

Definition at line 335 of file UiComponentFactory.php.

336  {
337  if (isset($bundleComponents[$name])) {
338  $bundleComponents[$name] = $reverseMerge
339  ? array_replace_recursive($data, $bundleComponents[$name])
340  : array_replace_recursive($bundleComponents[$name], $data);
341  return [$bundleComponents, true];
342  } else {
343  foreach ($bundleComponents as &$childData) {
344  if (isset($childData['attributes']['class'])
345  && is_a($childData['attributes']['class'], \Magento\Ui\Component\Container::class, true)
346  && isset($childData['children']) && is_array($childData['children'])
347  ) {
348  list($childData['children'], $isMerged) = $this->mergeMetadataElement(
349  $childData['children'],
350  $name,
351  $data,
352  $reverseMerge
353  );
354  if ($isMerged) {
355  return [$bundleComponents, true];
356  }
357  }
358  }
359  }
360  return [$bundleComponents, false];
361  }
mergeMetadataElement(array $bundleComponents, $name, array $data, $reverseMerge=false)
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ mergeMetadataItem()

mergeMetadataItem ( array  $bundleComponents,
array  $metadata,
  $reverseMerge = false 
)
protected

Merge metadata item to components

Parameters
array$bundleComponents
array$metadata
bool$reverseMerge
Returns
array
Exceptions
LocalizedException
Since
100.1.0

Definition at line 373 of file UiComponentFactory.php.

374  {
375  foreach ($metadata as $name => $data) {
376  $selfData = $data;
377  if (isset($selfData['children'])) {
378  unset($selfData['children']);
379  }
380 
381  list($bundleComponents, $isMerged) = $this->mergeMetadataElement(
382  $bundleComponents,
383  $name,
384  $selfData,
385  $reverseMerge
386  );
387 
388  if (!$isMerged) {
389  if (!isset($data['arguments']['data']['config']['componentType'])) {
390  throw new LocalizedException(new Phrase(
391  'The "componentType" configuration parameter is required for the "%1" component.',
392  [$name]
393  ));
394  }
395  $rawComponentData = $this->definitionData->get(
396  $data['arguments']['data']['config']['componentType']
397  );
398  list(, $componentArguments) = $this->argumentsResolver($name, $rawComponentData);
399  $arguments = array_replace_recursive($componentArguments, $data['arguments']);
401 
402  $bundleComponents[$name] = $rawComponentData;
403  $bundleComponents[$name]['children'] = [];
404  }
405 
406  if (isset($data['children']) && is_array($data['children'])) {
407  $bundleComponents[$name]['children'] = $this->mergeMetadataItem(
408  $bundleComponents[$name]['children'],
409  $data['children'],
410  $reverseMerge
411  );
412  }
413  }
414 
415  return $bundleComponents;
416  }
$arguments
mergeMetadataElement(array $bundleComponents, $name, array $data, $reverseMerge=false)
mergeMetadataItem(array $bundleComponents, array $metadata, $reverseMerge=false)
argumentsResolver($identifier, array $componentData)
if(!isset($_GET['name'])) $name
Definition: log.php:14

Field Documentation

◆ $argumentInterpreter

$argumentInterpreter
protected

Definition at line 43 of file UiComponentFactory.php.

◆ $componentManager

$componentManager
protected

Definition at line 56 of file UiComponentFactory.php.

◆ $contextFactory

$contextFactory
protected

Definition at line 48 of file UiComponentFactory.php.

◆ $objectManager

$objectManager
protected

Definition at line 36 of file UiComponentFactory.php.


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