I have 3 related Database tables (inventory, sale, sale_details) i would like to be able to make a form that can handle creating a Sale.
The problem is with my custom field "InventoryType" which should map correctly to an entity in the Database.
NOTE: Inventory are stored uniquely on their serial number.
I have created 3 custom field types, "InventoryType, SaleDetailsType, SaleType",
The InventoryType holds data equal to a Inventory table and (Inventory.php Entity)
The SaleDetailsType holds one InventoryType,
And the SaleType holds a collection of SaleDetailsTypes, account information and more.
I've tried with an InventoryToSerialNumberTransformer file to transform a Serial number into an inventory so that the InventoryType field only contains the serial number.
// src/Form/Type/InventoryType.php
$builder->add('serialNumber', TextType::class, ['label' => 'Serialnumber'])
// src/Form/Type/SaleDetailsType.php
$builder->add('Inventory', InventoryType::class, ['label' => 'Inventory item']);
// src/Form/Type/SaleType.php
$builder->add('account', EntityType::class, [ 'class' => Account::class ])
->add('shop', EntityType::class, [ 'shop' => Shop::class ])
->add('saledetails', CollectionType::class, [ 'entry_type' => SaleDetailsType::class,
'entry_options' => ['label' => false],
'allow_add' => true ])
->add('save', SubmitType::class, ['label' => 'Create Sale!']);
{{ form_start(form) }}
{{ form_row(form.account) }}
{{ form_row(form.shop) }}
<h3>Saledetails</h3>
<ul class="saledetails">
{% for detail in form.saledetails %}
{% for inventory in detail %}
<li> {{ form_row(inventory.serialNumber) }}</li>
{% endfor %}
{% endfor %}
</ul>
{{ form_row(form.save) }}
{{ form_row(form._token) }}
Expected behavior:
When adding list items via clientside JavaScript that is identical to the format that symfony uses (this is already done and works perfectly) the "inventory" should be correctly inserted just from the serial number alone.