private function _retrieveData() { if ($this->isFormSent()) { $this->data = array(); $fields = $this->template->getFields(); foreach ($fields as $field) { $name = str_replace($this->templateName . "_", "", $field->getName()); $field->setValue($_POST[$field->getName()]); $this->data[$name] = $field->getValue(); } } $this->template->setData($this->data); return $this->data; }
public function testToHtml() { $data = []; $id = 1; $nameInLayout = 'test-name'; $blockName = $nameInLayout . '-' . $id . '-button'; $expectedHtml = 'test html'; $blockButtonMock = $this->getMock(Container::DEFAULT_BUTTON, [], [], '', false); $blockButtonMock->expects($this->once())->method('toHtml')->willReturn($expectedHtml); $contextMock = $this->getMock('Magento\\Framework\\View\\Element\\Template\\Context', [], [], '', false); $eventManagerMock = $this->getMockForAbstractClass('Magento\\Framework\\Event\\ManagerInterface'); $contextMock->expects($this->any())->method('getEventManager')->willReturn($eventManagerMock); $scopeConfigMock = $this->getMockForAbstractClass('Magento\\Framework\\App\\Config\\ScopeConfigInterface'); $scopeConfigMock->expects($this->any())->method('getValue')->withAnyParameters()->willReturn(false); $contextMock->expects($this->any())->method('getScopeConfig')->willReturn($scopeConfigMock); $layoutMock = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false); $layoutMock->expects($this->once())->method('createBlock')->with(Container::DEFAULT_BUTTON, $blockName)->willReturn($blockButtonMock); $contextMock->expects($this->any())->method('getLayout')->willReturn($layoutMock); $itemMock = $this->getMock('Magento\\Ui\\Component\\Control\\Item', [], [], '', false); $itemMock->expects($this->any())->method('getData')->willReturn($data); $itemMock->expects($this->any())->method('getId')->willReturn($id); $abstractContextMock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\AbstractBlock')->disableOriginalConstructor()->setMethods(['getNameInLayout'])->getMockForAbstractClass(); $abstractContextMock->expects($this->any())->method('getNameInLayout')->willReturn($nameInLayout); $container = new Container($contextMock); $container->setButtonItem($itemMock); $container->setData('context', $abstractContextMock); $this->assertEquals($expectedHtml, $container->toHtml()); }
public function render() { $id = "multiform-" . $this->index; $this->setId($id); $attributes = $this->getAttributes(); if ($this->data == null) { $this->_retrieveData(); } if ($this->template != null) { $this->template->clearErrors(); $template = $this->template->render(); $count = 0; foreach ($this->data as $index => $data) { foreach ($data as $key => $dat) { $data[$this->templateName . "." . $key . "[]"] = $dat; } //$this->clearErrors(); $this->template->setData($data); //$retval = $this->template->validate(); $this->template->setId("multiform-content-" . $index); $this->template->getElementById("multi-form-buttons")->buttons[0]->addAttribute("onclick", "fapiMultiFormRemove('{$index}')"); $contents .= "<div id='multi-form-content-{$index}'>" . $this->template->render() . "</div>"; } } $ret = "<div {$attributes} >\n <input type='hidden' id='multiform-numitems-{$this->index}' value='{$count}'/>\n <div id='multiform-contents-{$this->index}'>\n {$contents}\n </div>"; $ret .= $this->getShowField() ? "<div class='fapi-multiform-bar'><span onclick='fapiMultiFormAdd({$this->index})' style='font-size:smaller;cursor:pointer'>Add New</span></div>" : ""; $ret .= "</div>\n <div id='multiform-template-{$this->index}' style='display:none'>\n {$template}\n </div>"; return $ret; }