|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LAG\AdminBundle\Form\Handler; |
|
4
|
|
|
|
|
5
|
|
|
use LAG\AdminBundle\Admin\Behaviors\EntityLabel; |
|
6
|
|
|
use LAG\AdminBundle\Form\Type\BatchActionType; |
|
7
|
|
|
use Symfony\Component\Form\FormFactory; |
|
8
|
|
|
use Symfony\Component\Form\FormInterface; |
|
9
|
|
|
|
|
10
|
|
|
class BatchFormHandler |
|
11
|
|
|
{ |
|
12
|
|
|
use EntityLabel; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var FormFactory |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $formFactory; |
|
18
|
|
|
|
|
19
|
|
|
public function __construct(FormFactory $formBuilder) |
|
20
|
|
|
{ |
|
21
|
|
|
$this->formFactory = $formBuilder; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Return entities checked by user |
|
26
|
|
|
* |
|
27
|
|
|
* @param FormInterface $form |
|
28
|
|
|
* @return FormInterface |
|
29
|
|
|
*/ |
|
30
|
|
|
public function handle(FormInterface $form) |
|
31
|
|
|
{ |
|
32
|
|
|
$data = $form->getData(); |
|
33
|
|
|
// TODO sort entities by id ? |
|
34
|
|
|
$entities = $data['entities']; |
|
35
|
|
|
$bacthItems = []; |
|
36
|
|
|
$batchEntities = []; |
|
37
|
|
|
|
|
38
|
|
|
// find batch items checkbox values |
|
39
|
|
|
foreach ($data as $name => $batchItem) { |
|
40
|
|
|
if (substr($name, 0, 6) == 'batch_') { |
|
41
|
|
|
$bacthItems[$name] = $batchItem; |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
// check if they exists in entities displayed and if checkbox is checked |
|
45
|
|
|
foreach ($bacthItems as $name => $bacthItem) { |
|
46
|
|
|
$batchId = (int)str_replace('batch_', '', $name); |
|
47
|
|
|
|
|
48
|
|
|
if (array_key_exists($batchId, $entities) && $bacthItem === true) { |
|
49
|
|
|
$batchEntities[$batchId] = $this->getEntityLabel($entities[$batchId]); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
// TODO get action from configuration |
|
53
|
|
|
$action = 'lag.admin.batch.delete'; |
|
54
|
|
|
|
|
55
|
|
|
$form = $this |
|
56
|
|
|
->formFactory |
|
57
|
|
|
->create(new BatchActionType(), [ |
|
|
|
|
|
|
58
|
|
|
'entities_ids' => array_keys($batchEntities), |
|
59
|
|
|
'entities_labels' => $batchEntities, |
|
60
|
|
|
'batch_action' => $data['batch'] |
|
61
|
|
|
], [ |
|
62
|
|
|
'action' => $action |
|
63
|
|
|
]); |
|
64
|
|
|
|
|
65
|
|
|
return $form; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: