/** * @param EmbeddedForm $formEntity * @param FormInterface $form * * @return Layout */ public function getLayout(EmbeddedForm $formEntity, FormInterface $form = null) { $formTypeName = $formEntity->getFormType(); $customLayout = $this->formManager->getCustomFormLayoutByFormType($formTypeName); $layoutContext = new LayoutContext(); $layoutContext->getResolver()->setRequired(['embedded_form_type'])->setOptional(['embedded_form', 'embedded_form_custom_layout']); $layoutContext->set('theme', 'embedded_default'); $layoutContext->set('embedded_form', null === $form ? null : new FormAccessor($form)); $layoutContext->set('embedded_form_type', $formTypeName); $layoutContext->set('embedded_form_custom_layout', $customLayout); $layoutContext->data()->set('embedded_form_entity', '', $formEntity); $layoutBuilder = $this->layoutManager->getLayoutBuilder(); // TODO discuss adding root automatically $layoutBuilder->add('root', null, 'root'); return $layoutBuilder->getLayout($layoutContext); }
/** * @param ResultRecordInterface $record * * @return mixed */ protected function getRawValue(ResultRecordInterface $record) { return $this->translator->trans($this->manager->getLabelByType($record->getValue('formType'))); }
/** * {@inheritdoc} */ public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(['choices' => $this->manager->getAll()]); }
/** * @test * @dataProvider customLayoutTypesProvider */ public function shouldReturnCustomFormLayoutByFormType($typeInstance, $expectedLayout) { $container = $this->createContainerMock($typeInstance); $formFactory = $this->createFormFactoryMock(); $type = 'type'; $manager = new EmbeddedFormManager($container, $formFactory); $this->assertEquals($expectedLayout, $manager->getCustomFormLayoutByFormType($type)); }