/**
  * Create component object
  *
  * @param string $identifier
  * @param string $name
  * @param array $arguments
  * @return UiComponentInterface
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function create($identifier, $name = null, array $arguments = [])
 {
     if ($name === null) {
         $bundleComponents = $this->componentManager->prepareData($identifier)->getData($identifier);
         if (empty($bundleComponents)) {
             throw new LocalizedException(new \Magento\Framework\Phrase('You use an empty set.'));
         }
         list($className, $componentArguments) = $this->argumentsResolver($identifier, $bundleComponents[$identifier]);
         $componentArguments = array_replace_recursive($componentArguments, $arguments);
         if (!isset($componentArguments['context'])) {
             $componentArguments['context'] = $this->contextFactory->create(['namespace' => $identifier]);
         }
         $componentContext = $componentArguments['context'];
         $components = [];
         foreach ($bundleComponents[$identifier]['children'] as $childrenIdentifier => $childrenData) {
             $children = $this->createChildComponent($childrenData, $componentContext, $childrenIdentifier);
             $components[$childrenIdentifier] = $children;
         }
         $components = array_filter($components);
         $componentArguments['components'] = $components;
         /** @var \Magento\Framework\View\Element\UiComponentInterface $component */
         $component = $this->objectManager->create($className, array_replace_recursive($componentArguments, $arguments));
         return $component;
     } else {
         $defaultData = $this->componentManager->createRawComponentData($name);
         list($className, $componentArguments) = $this->argumentsResolver($identifier, $defaultData);
         /** @var \Magento\Framework\View\Element\UiComponentInterface $component */
         $component = $this->objectManager->create($className, array_replace_recursive($componentArguments, $arguments));
         return $component;
     }
 }
Exemple #2
0
 /**
  * Create component object
  *
  * @param Structure $structure
  * @param string $elementName
  * @param string $data
  * @param LayoutInterface $layout
  * @return ContainerInterface
  */
 protected function generateComponent(Structure $structure, $elementName, $data, LayoutInterface $layout)
 {
     $attributes = $data['attributes'];
     if (!empty($attributes['group'])) {
         $structure->addToParentGroup($elementName, $attributes['group']);
     }
     $context = $this->contextFactory->create(['namespace' => $elementName, 'pageLayout' => $layout]);
     $component = $this->uiComponentFactory->create($elementName, null, ['context' => $context]);
     $this->prepareComponent($component);
     /** @var ContainerInterface $blockContainer */
     $blockContainer = $this->blockFactory->createBlock(static::CONTAINER, ['component' => $component]);
     return $blockContainer;
 }