1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Setono\SyliusStockMovementPlugin\Form\Type\Api; |
6
|
|
|
|
7
|
|
|
use Sylius\Bundle\ResourceBundle\Form\DataTransformer\ResourceToIdentifierTransformer; |
8
|
|
|
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; |
9
|
|
|
use Sylius\Component\Product\Repository\ProductVariantRepositoryInterface; |
10
|
|
|
use Symfony\Component\Form\Extension\Core\Type\IntegerType; |
11
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
12
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
13
|
|
|
|
14
|
|
|
final class StockMovementType extends AbstractResourceType |
15
|
|
|
{ |
16
|
|
|
/** @var ProductVariantRepositoryInterface */ |
17
|
|
|
private $variantRepository; |
18
|
|
|
|
19
|
|
|
public function __construct( |
20
|
|
|
string $dataClass, |
21
|
|
|
ProductVariantRepositoryInterface $variantRepository, |
22
|
|
|
$validationGroups = [] |
23
|
|
|
) { |
24
|
|
|
parent::__construct($dataClass, $validationGroups); |
25
|
|
|
|
26
|
|
|
$this->variantRepository = $variantRepository; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options): void |
30
|
|
|
{ |
31
|
|
|
$builder |
32
|
|
|
->add('quantity', IntegerType::class, [ |
33
|
|
|
'label' => 'setono_sylius_stock_movement.form.stock_movement.quantity', |
34
|
|
|
]) |
35
|
|
|
->add('reference', TextType::class, [ |
36
|
|
|
'label' => 'setono_sylius_stock_movement.form.stock_movement.reference', |
37
|
|
|
]) |
38
|
|
|
->add('variant', TextType::class, [ |
39
|
|
|
'label' => 'setono_sylius_stock_movement.form.stock_movement.variant', |
40
|
|
|
'invalid_message' => 'setono_sylius_stock_movement.stock_movement.variant_invalid', |
41
|
|
|
]) |
42
|
|
|
; |
43
|
|
|
|
44
|
|
|
$builder->get('variant')->addModelTransformer( |
45
|
|
|
new ResourceToIdentifierTransformer($this->variantRepository, 'code') |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getBlockPrefix(): string |
50
|
|
|
{ |
51
|
|
|
return 'setono_sylius_stock_movement_api_stock_movement'; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|