add orderstuff

This commit is contained in:
lubiana 2025-06-14 22:43:27 +02:00
parent 51fb951b2b
commit d7a61f6d0e
Signed by: lubiana
SSH key fingerprint: SHA256:vW1EA0fRR3Fw+dD/sM0K+x3Il2gSry6YRYHqOeQwrfk
9 changed files with 209 additions and 10 deletions

View file

@ -5,7 +5,10 @@ declare(strict_types=1);
namespace App\Form;
use App\Entity\Order;
use App\Enum\OrderStatus;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
@ -14,7 +17,15 @@ class OrderForm extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('status')
->add('status', EnumType::class, ['class' => OrderStatus::class])
->add('orderItems', CollectionType::class, [
'entry_type' => OrderItemType::class,
'entry_options' => ['label' => false],
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'label' => 'Order Items',
])
;
}

View file

@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
namespace App\Form;
use App\Entity\DrinkType;
use App\Entity\OrderItem;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Symfony\Component\Validator\Constraints\NotNull;
class OrderItemType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('drinkType', EntityType::class, [
'class' => DrinkType::class,
'choice_label' => 'name',
'placeholder' => 'Select a drink type',
'required' => true,
'constraints' => [
new NotNull(message: 'Please select a drink type'),
],
])
->add('quantity', IntegerType::class, [
'required' => true,
'constraints' => [
new NotNull(message: 'Please enter a quantity'),
new GreaterThan(value: 0, message: 'Quantity must be greater than 0'),
],
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => OrderItem::class,
]);
}
}