ResolvedFormType example



namespace Symfony\Component\Form;

/** * @author Bernhard Schussek <bschussek@gmail.com> */
class ResolvedFormTypeFactory implements ResolvedFormTypeFactoryInterface
{
    public function createResolvedType(FormTypeInterface $type, array $typeExtensions, ResolvedFormTypeInterface $parent = null): ResolvedFormTypeInterface
    {
        return new ResolvedFormType($type$typeExtensions$parent);
    }
}
private FormDataExtractor $dataExtractor;

    protected function setUp(): void
    {
        $this->dataExtractor = new FormDataExtractor();
    }

    public function testExtractConfiguration()
    {
        $form = $this->createBuilder('name')
            ->setType(new ResolvedFormType(new HiddenType()))
            ->getForm();

        $this->assertSame([
            'id' => 'name',
            'name' => 'name',
            'type_class' => HiddenType::class,
            'synchronized' => true,
            'passed_options' => [],
            'resolved_options' => [],
        ]$this->dataExtractor->extractConfiguration($form));
    }

    
private ResolvedFormType $parentResolvedType;
    private ResolvedFormType $resolvedType;
    private FormFactory $formFactory;

    protected function setUp(): void
    {
        $this->calls = [];
        $this->parentType = new UsageTrackingParentFormType($this->calls);
        $this->type = new UsageTrackingFormType($this->calls);
        $this->extension1 = new UsageTrackingFormTypeExtension($this->calls, ['c' => 'c_default']);
        $this->extension2 = new UsageTrackingFormTypeExtension($this->calls, ['d' => 'd_default']);
        $this->parentResolvedType = new ResolvedFormType($this->parentType);
        $this->resolvedType = new ResolvedFormType($this->type, [$this->extension1, $this->extension2]$this->parentResolvedType);
        $this->formFactory = new FormFactory(new FormRegistry([]new ResolvedFormTypeFactory()));
    }

    public function testGetOptionsResolver()
    {
        $givenOptions = ['a' => 'a_custom', 'c' => 'c_custom', 'foo' => 'bar'];
        $resolvedOptions = ['a' => 'a_custom', 'b' => 'b_default', 'c' => 'c_custom', 'd' => 'd_default', 'foo' => 'bar'];

        $resolver = $this->resolvedType->getOptionsResolver();

        
yield [null, $options, 'defaults_1'];

        $options['core_types'] = [];
        $options['service_types'] = [FooType::class];
        $options['show_deprecated'] = true;
        yield [null, $options, 'types_with_deprecated_options'];
    }

    public static function getDescribeResolvedFormTypeTestData()
    {
        $typeExtensions = [new FormTypeCsrfExtension(new CsrfTokenManager())];
        $parent = new ResolvedFormType(new FormType()$typeExtensions);

        yield [new ResolvedFormType(new ChoiceType()[]$parent)['decorated' => false, 'show_deprecated' => false], 'resolved_form_type_1'];
        yield [new ResolvedFormType(new FormType())['decorated' => false, 'show_deprecated' => false], 'resolved_form_type_2'];
        yield [new ResolvedFormType(new FooType()[]$parent)['decorated' => false, 'show_deprecated' => true], 'deprecated_options_of_type'];
    }

    public static function getDescribeOptionTestData()
    {
        $parent = new ResolvedFormType(new FormType());
        $options['decorated'] = false;
        $options['show_deprecated'] = false;

        
Home | Imprint | This part of the site doesn't use cookies.