10 use Magento\Framework\Config\DataInterfaceFactory;
61 private $componentChildFactories;
66 private $configFactory;
71 private $definitionData;
89 array $componentChildFactories = [],
91 DataInterfaceFactory $configFactory =
null 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);
114 array &$bundleComponents,
119 $componentArguments = &$bundleComponents[
'arguments'];
121 if (isset($componentArguments[
'data'][
'disabled']) && (
int)$componentArguments[
'data'][
'disabled']) {
128 $bundleComponents[
'components'] = [];
129 $components = &$bundleComponents[
'components'];
131 if (isset($this->componentChildFactories[
$className])) {
140 foreach ($bundleComponents[
'children'] as $childrenIdentifier => $childrenData) {
147 $components[$childrenIdentifier] =
$children;
150 $components = array_filter($components);
151 $componentArguments[
'components'] = $components;
156 if (isset($componentArguments[
'block']) && !$componentArguments[
'block']) {
160 if (!isset($componentArguments[
'context'])) {
161 $componentArguments[
'context'] = $renderContext;
164 return $this->objectManager->create(
$className, $componentArguments);
200 public function create($identifier,
$name =
null, array
$arguments = [])
202 if (
$name ===
null) {
203 $componentData = $this->configFactory->create([
'componentName' => $identifier])->get($identifier);
204 $bundleComponents = [$identifier => $componentData];
208 $bundleComponents[$identifier]
210 $componentArguments = array_replace_recursive($componentArguments,
$arguments);
211 if (!isset($componentArguments[
'context'])) {
212 $componentArguments[
'context'] = $this->contextFactory->create(
213 [
'namespace' => $identifier]
216 $reverseMerge = isset($componentArguments[
'data'][
'reverseMetadataMerge'])
217 && $componentArguments[
'data'][
'reverseMetadataMerge'];
218 $bundleComponents = $this->
mergeMetadata($identifier, $bundleComponents, $reverseMerge);
219 $children = $bundleComponents[$identifier][
'children'];
221 $rawComponentData = $this->definitionData->get(
$name);
223 $componentArguments = array_replace_recursive($componentArguments,
$arguments);
224 $children = isset($componentArguments[
'data'][
'config'][
'children']) ?
225 $componentArguments[
'data'][
'config'][
'children'] : [];
229 $className = isset($componentArguments[
'config'][
'class']) ?
230 $componentArguments[
'config'][
'class'] :
$className;
233 foreach (
$children as $childrenIdentifier => $childrenData) {
236 $componentArguments[
'context'],
240 $components[$childrenIdentifier] =
$children;
243 $components = array_filter($components);
244 $componentArguments[
'components'] = $components;
247 $component = $this->objectManager->create(
265 $bundleChildren = [];
268 if (!isset(
$config[
'componentType'])) {
270 'The "componentType" configuration parameter is required for the "%1" component.',
275 if (!isset($componentArguments[
'context'])) {
278 'An error occurred with the UI component. Each component needs context. Verify and try again.' 283 $rawComponentData = $this->definitionData->get(
$config[
'componentType']);
284 list(, $componentArguments) = $this->
argumentsResolver($identifier, $rawComponentData);
285 $arguments = array_replace_recursive($componentArguments, [
'data' => [
'config' =>
$config]]);
288 $bundleChildren[$identifier] = $rawComponentData;
289 $bundleChildren[$identifier][
'children'] = [];
291 if (isset(
$arguments[
'data'][
'config'][
'children'])) {
298 return $bundleChildren;
310 protected function mergeMetadata($identifier, array $bundleComponents, $reverseMerge =
false)
312 $dataProvider = $this->
getDataProvider($identifier, $bundleComponents);
316 'children' => $dataProvider->getMeta(),
319 $bundleComponents = $this->
mergeMetadataItem($bundleComponents, $metadata, $reverseMerge);
322 return $bundleComponents;
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];
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'])
349 $childData[
'children'],
355 return [$bundleComponents,
true];
360 return [$bundleComponents,
false];
373 protected function mergeMetadataItem(array $bundleComponents, array $metadata, $reverseMerge =
false)
377 if (isset($selfData[
'children'])) {
378 unset($selfData[
'children']);
389 if (!isset(
$data[
'arguments'][
'data'][
'config'][
'componentType'])) {
391 'The "componentType" configuration parameter is required for the "%1" component.',
395 $rawComponentData = $this->definitionData->get(
396 $data[
'arguments'][
'data'][
'config'][
'componentType']
399 $arguments = array_replace_recursive($componentArguments,
$data[
'arguments']);
402 $bundleComponents[
$name] = $rawComponentData;
403 $bundleComponents[
$name][
'children'] = [];
406 if (isset(
$data[
'children']) && is_array(
$data[
'children'])) {
408 $bundleComponents[
$name][
'children'],
415 return $bundleComponents;
428 foreach ($bundleComponents[$identifier][
'children'] as $childrenData) {
429 if (isset($childrenData[
'arguments'][
'dataProvider'])
432 return $childrenData[
'arguments'][
'dataProvider'];
__construct(ObjectManagerInterface $objectManager, ManagerInterface $componentManager, InterpreterInterface $argumentInterpreter, ContextFactory $contextFactory, array $data=[], array $componentChildFactories=[], DataInterface $definitionData=null, DataInterfaceFactory $configFactory=null)
const COMPONENT_ARGUMENTS_KEY
getBundleChildren(array $children=[])
const COMPONENT_ATTRIBUTES_KEY
mergeMetadata($identifier, array $bundleComponents, $reverseMerge=false)
getDataProvider($identifier, array $bundleComponents)
mergeMetadataElement(array $bundleComponents, $name, array $data, $reverseMerge=false)
createChildComponent(array &$bundleComponents, ContextInterface $renderContext, $identifier, array $arguments=[])
mergeMetadataItem(array $bundleComponents, array $metadata, $reverseMerge=false)
argumentsResolver($identifier, array $componentData)
if(!isset($_GET['name'])) $name