I would like to create form based on dynamic parameters that are stored in DB. So I've created an entity called Parameter that defines parameter name, which should be displayed as form field label.
/**
* @ORM\Entity
*/
class Parameter
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length="255")
* @Assert\NotBlank()
*/
protected $name;
/**
* @ORM\OneToMany(targetEntity="ParameterValue", mappedBy="parameter")
*/
protected $values;
Parameter values for specific object (Company object) are about to be stored in ParameterValue tabel.
/**
* @ORM\Entity
*/
class ParameterValue
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Parameter", inversedBy="values")
* @ORM\JoinColumn(name="parameter_id", referencedColumnName="id", nullable=false)
*/
protected $parameter;
/**
* @ORM\ManyToOne(targetEntity="Company", inversedBy="parameters")
* @ORM\JoinColumn(name="company_id", referencedColumnName="id", nullable=false)
*/
protected $company;
And of course Company entity contains parameters attribute that stores only those parameters that has been specified for Company.
/**
* @ORM\Entity
*/
class Company
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length="255")
*/
protected $name;
/**
* @ORM\OneToMany(targetEntity="ParameterValue", mappedBy="hotel")
*/
protected $parameters;
How can I create Form that dynamically fetches all Parameters from DB, creates text fields with specific labels (label=Parameter->getName()) and gets ParameterValues for parameters that has already been associated with Company (for edit action)?
I have already created 'collection' field that gets ParameterValues but the problem is that I get form with fields for parameters that has been used for Company but no others. And of course I cannot get label because collection field type is ParameterType not Parameter.