/** * @depends testSetEntity */ public function getTemplateForm(Collection $collection) { $this->collectionContainer->setEntity($collection); $form = $this->collectionContainer->getTemplateForm(); $this->assertInstanceOf(CoreForm::class, $form); $this->assertNull($form->getObject()); $this->assertContains(CollectionContainer::NEW_ENTRY, $form->getAttribute('action')); }
/** * Renders the forms of a container. * * @param CollectionContainer $container * @param string $layout * @param array $parameter * @return string */ public function render(CollectionContainer $container, $layout = Form::LAYOUT_HORIZONTAL, $parameter = []) { $view = $this->getView(); $view->headscript()->appendFile($view->basePath('Core/js/jquery.formcollection-container.js')); $translator = $this->getTranslator(); $formContainerHelper = $view->formContainer(); $formsMarkup = ''; $formTemplateWrapper = '<div class="form-collection-container-form"> ' . ($this->displayRemoveButton ? '<button type="button" class="btn btn-sm btn-danger pull-right form-collection-container-remove-button">' . $translator->translate('Remove') . '</button>' : '') . ' %s </div>'; foreach ($container as $form) { $formsMarkup .= sprintf($formTemplateWrapper, $formContainerHelper->renderElement($form, $layout, $parameter)); } $templateForm = $container->getTemplateForm(); $templateMarkup = sprintf($view->formCollection()->getTemplateWrapper(), $view->escapeHtmlAttr(sprintf($formTemplateWrapper, $formContainerHelper->renderElement($templateForm, $layout, $parameter)))); return sprintf('<div class="form-collection-container" data-new-entry-key="%s" data-remove-action="%s" data-remove-question="%s"> <h3>%s</h3> %s%s%s </div>', CollectionContainer::NEW_ENTRY, $container->formatAction('remove'), $translator->translate('Really remove?'), $container->getLabel(), $formsMarkup, $templateMarkup, '<div class="form-collection-container-add-wrapper"><button type="button" class="btn btn-success form-collection-container-add-button"><span class="yk-icon yk-icon-plus"></span> ' . sprintf($translator->translate('Add %s'), $container->getLabel()) . '</button></div>'); }