/** * {@inheritdoc} */ public function update(UiComponentInterface $component) { if (!$component instanceof \Magento\Ui\Component\Filters) { return; } $attributeCodes = $component->getContext()->getRequestParam('attributes_codes'); if ($attributeCodes) { foreach ($this->getAttributes($attributeCodes) as $attribute) { $filter = $this->filterFactory->create($attribute, $component->getContext()); $filter->prepare(); $component->addComponent($attribute->getAttributeCode(), $filter); } } }
/** * Create child of form * * @param UiComponentInterface $childComponent * @param string $name * @return UiComponentInterface * @throws \Magento\Framework\Exception\LocalizedException */ protected function createChildFormComponent(UiComponentInterface $childComponent, $name) { $panelComponent = $this->uiComponentFactory->create($name, $this->getConfig(self::CONFIG_PANEL_COMPONENT), ['context' => $this->component->getContext(), 'components' => [$childComponent->getName() => $childComponent]]); $panelComponent->prepare(); $this->component->addComponent($name, $panelComponent); return $panelComponent; }
/** * Generate Java Script configuration element * * @param UiComponentInterface $component * @return array */ public function build(UiComponentInterface $component) { $children = []; $context = $component->getContext(); $this->addChildren($children, $component, $component->getName()); $dataSources = $component->getDataSourceData(); $configuration = ['types' => $context->getComponentsDefinitions(), 'components' => [$context->getNamespace() => ['children' => array_merge($children, $dataSources)]]]; return $configuration; }
/** * Build * * @param UiComponentInterface $component * @return array */ public function build(UiComponentInterface $component) { $this->component = $component; $this->namespace = $component->getContext()->getNamespace(); $this->addNavigationBlock(); // Initialization of structure components $this->initSections(); $this->initAreas(); return parent::build($component); }
/** * Render data * * @param UiComponentInterface $component * @param string $template * @return string * @throws \Exception * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function render(UiComponentInterface $component, $template = '') { $context = $component->getContext(); $isComponent = $context->getRequestParam('componentJson'); if ($isComponent) { $data = $this->structure->generate($component); return $this->encoder->encode($data); } else { $data = $component->getContext()->getDataSourceData($component); $data = reset($data); return $this->encoder->encode($data['config']['data']); } }
/** * Add navigation block * * @return void */ protected function addNavigationBlock() { $pageLayout = $this->component->getContext()->getPageLayout(); /** @var \Magento\Ui\Component\Layout\Tabs\Nav $navBlock */ if (isset($this->navContainerName)) { $navBlock = $pageLayout->addBlock('Magento\\Ui\\Component\\Layout\\Tabs\\Nav', 'tabs_nav', $this->navContainerName); } else { $navBlock = $pageLayout->addBlock('Magento\\Ui\\Component\\Layout\\Tabs\\Nav', 'tabs_nav', 'content'); } $navBlock->setTemplate('Magento_Ui::layout/tabs/nav/default.phtml'); $navBlock->setData('data_scope', $this->namespace); $this->component->getContext()->addComponentDefinition('nav', ['component' => 'Magento_Ui/js/form/components/tab_group', 'config' => ['template' => 'ui/tab'], 'extends' => $this->namespace]); }
/** * Get configuration of related JavaScript Component * (force extending the root component if component does not extend other component) * * @param UiComponentInterface $component * @return array */ public function getJsConfig(UiComponentInterface $component) { $jsConfig = (array) $component->getData('js_config'); if (!isset($jsConfig['extends'])) { $jsConfig['extends'] = $component->getContext()->getNamespace(); } return $jsConfig; }
/** * Get JS configuration * * @param UiComponentInterface $component * @param null|string $extends * @return array */ protected function getConfiguration(UiComponentInterface $component, $extends = null) { $jsConfig = (array) $component->getData('js_config'); if (isset($jsConfig['extends'])) { return $jsConfig; } else { if (null !== $extends) { $jsConfig['extends'] = $extends; } else { $jsConfig['extends'] = $component->getContext()->getNamespace(); } } return $jsConfig; }