yoanbernabeu / Airtable-Client-Bundle

Simple Client for Airtable API
MIT License
33 stars 12 forks source link

[Feature request] Easy form creation #22

Closed yoanbernabeu closed 3 years ago

yoanbernabeu commented 3 years ago

I propose to add the possibility of using the Form Component of Symfony to facilitate the creation of an Airtable recording. For the moment I do not know how I will do it, but I get to work and propose a PR soon.

Concretely, in terms of use, I would see something like this :

class Foo
{
    public int $id;
    public string $bar;
}

class FooController
{
    public function bar(AirtableClientInterface $airtableClient, Request $request)
    {
        $foo = new Foo();

        $form = $airtableClient->createForm(['id', 'bar'], $foo);

        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $foo = $form->getData();
        $airtableClient->addOneRecord(
                        'tableName',
                         [
                            $foo,
                            Foo::class,
                         ]
            );  

            return $this->redirectToRoute('task_success');
        }

        return $this->render('foo/new.html.twig', [
                'form' => $form->createView(),
        ]);

    }
}