At work, we are testing several different PHP frameworks. In order to performance test them, we are implementing the same functionality in each one.
We have a REST specification that defines the routes and the data elements used. For example, for the route POST /sprints/create I need to include several fields in the post data, like csrf, sprint_label, sprint_points.
I've created an entity with Label and Points, and a FormType to create the form, but I cannot find any way to change the generated name attributes in the HTML form, which eventually define the POST data names.
I've tried added an {attr: {'name': 'sprint_label'}} in the twig template, but apparently it is just ignored (reserved word I imagine). I've looked at Data Transformers, but it seems to me that the entity property name are tightly coupled to the generated form field names.
I thought about writing an form entity wrapper to remap the names, but I don't understand the magic that happens (which methods are called, with which parameters) between the form generation after the post, and entity manager persist...
Does anyone have any idea how to customize the generated form field names?
Thanks, Sam
Form Code:
<?php
namespace Blah\AppBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class SprintType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title', 'text')
->add('points', 'integer')
->add('Save', 'submit');
}
public function getName()
{
return ''; // this removes the sprint[title] name, leaving just title.
}
}