public function testAdd() { $data = ['id' => 'id']; $this->itemFactoryMock->expects($this->any())->method('create')->willReturn($this->items[$this->key]); $this->items[$this->key]->expects($this->any())->method('setData')->with($data)->willReturnSelf(); $this->contextMock->expects($this->any())->method('getPageLayout')->willReturn($this->layoutMock); $toolbarContainerMock = $this->getMock('Magento\\Backend\\Block\\Widget\\Button\\Toolbar\\Container', [], [], '', false); $this->layoutMock->expects($this->once())->method('createBlock')->with('Magento\\Ui\\Component\\Control\\Container', 'container-' . $this->key, ['data' => ['button_item' => $this->items[$this->key], 'context' => $this->uiComponentInterfaceMock]])->willReturn($toolbarContainerMock); $this->toolbarBlockMock->expects($this->once())->method('setChild')->with($this->key, $toolbarContainerMock)->willReturnSelf(); $this->actionPool->add($this->key, $data, $this->uiComponentInterfaceMock); }
/** * Prepare component data * * @return void */ public function prepare() { $this->registerComponents(); $buttons = $this->getData('buttons'); if ($buttons) { foreach ($buttons as $buttonId => $buttonClass) { /** @var ButtonProviderInterface $button */ $button = $this->buttonProviderFactory->create($buttonClass); $buttonData = $button->getButtonData(); if (!$buttonData) { unset($buttons[$buttonId]); continue; } $buttons[$buttonId] = $buttonData; } uasort($buttons, [$this, 'sortButtons']); foreach ($buttons as $buttonId => $buttonData) { $this->actionPool->add($buttonId, $buttonData, $this); } } $layoutSettings = (array) $this->getData('layout'); $data = ['name' => $this->getData('name'), 'label' => $this->getData('label'), 'data_sources' => $this->getData('data_sources'), 'child_blocks' => $this->getLayout()->getChildBlocks($this->getNameInLayout()), 'configuration' => isset($layoutSettings['configuration']) ? $layoutSettings['configuration'] : []]; $layoutType = isset($layoutSettings['type']) ? $layoutSettings['type'] : \Magento\Ui\Component\Layout\Tabs::NAME; $layout = $this->factory->create($layoutType, $data); $layout->prepare(); $this->elements[] = $layout; }
/** * Prepare custom data * * @return void */ public function prepare() { $meta = $this->getMeta(); $defaultConfigData = $this->getDefaultConfiguration(); if ($this->hasData('configuration')) { $configData = $this->getData('configuration'); if (!empty($configData['page_actions'])) { foreach ($configData['page_actions'] as $key => $action) { $defaultConfigData['page_actions'][$key] = isset($configData['page_actions']) ? array_replace($defaultConfigData['page_actions'][$key], $configData['page_actions'][$key]) : $defaultConfigData['page_actions'][$key]; } } unset($configData['page_actions']); $defaultConfigData = array_merge($defaultConfigData, $configData); } foreach ($defaultConfigData['page_actions'] as $key => $action) { $this->actionPool->add($key, $action, $this); } unset($defaultConfigData['page_actions']); $this->prepareConfiguration($defaultConfigData, $this->getData('name')); $this->renderContext->getStorage()->addMeta($this->getData('name'), $meta); $this->renderContext->getStorage()->addDataCollection($this->getData('name'), $this->getData('dataSource')); }