|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright CONTENT CONTROL GmbH, http://www.contentcontrol-berlin.de |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace midcom\datamanager\extension\type; |
|
7
|
|
|
|
|
8
|
|
|
use midcom\datamanager\storage\container\dbacontainer; |
|
9
|
|
|
use Symfony\Component\Form\FormInterface; |
|
10
|
|
|
use Symfony\Component\Form\FormView; |
|
11
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
12
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
|
13
|
|
|
use Symfony\Component\Form\AbstractType; |
|
14
|
|
|
use midcom\datamanager\controller; |
|
15
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Experimental toolbar type |
|
19
|
|
|
*/ |
|
20
|
|
|
class toolbarType extends AbstractType |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* {@inheritdoc} |
|
24
|
|
|
*/ |
|
25
|
1 |
|
public function configureOptions(OptionsResolver $resolver) |
|
26
|
|
|
{ |
|
27
|
1 |
|
$resolver->setDefaults([ |
|
28
|
1 |
|
'operations' => [], |
|
29
|
1 |
|
'mapped' => false |
|
30
|
1 |
|
]); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* {@inheritdoc} |
|
35
|
|
|
*/ |
|
36
|
152 |
|
public function buildForm(FormBuilderInterface $builder, array $options) |
|
37
|
|
|
{ |
|
38
|
152 |
|
foreach ($options['operations'] as $operation => $button_labels) { |
|
39
|
152 |
|
foreach ((array) $button_labels as $key => $label) { |
|
40
|
152 |
|
$attributes = [ |
|
41
|
152 |
|
'operation' => $operation, |
|
42
|
152 |
|
'label' => $label, |
|
43
|
152 |
|
'attr' => ['class' => 'submit ' . $operation] |
|
44
|
152 |
|
]; |
|
45
|
152 |
|
if ($operation == controller::SAVE) { |
|
46
|
151 |
|
$attributes['attr']['accesskey'] = 's'; |
|
47
|
151 |
|
$attributes['attr']['class'] .= ' save_' . $key; |
|
48
|
149 |
|
} elseif ($operation == controller::CANCEL) { |
|
49
|
149 |
|
$attributes['attr']['accesskey'] = 'd'; |
|
50
|
149 |
|
$attributes['attr']['formnovalidate'] = true; |
|
51
|
2 |
|
} elseif ($operation == controller::PREVIOUS) { |
|
52
|
|
|
$attributes['attr']['formnovalidate'] = true; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
152 |
|
$builder->add($operation . $key, SubmitType::class, $attributes); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
148 |
|
public function buildView(FormView $view, FormInterface $form, array $options) |
|
61
|
|
|
{ |
|
62
|
148 |
|
$view->vars['button-labels'] = []; |
|
63
|
148 |
|
foreach ($form->all() as $key => $button) { |
|
64
|
148 |
|
$label = $button->getConfig()->getOption('label'); |
|
65
|
148 |
|
if (!$label) { |
|
66
|
144 |
|
$operation = $button->getConfig()->getOption('operation'); |
|
67
|
144 |
|
$storage = $view->parent->vars['value']; |
|
68
|
|
|
|
|
69
|
144 |
|
if ( $operation == controller::SAVE |
|
70
|
144 |
|
&& $storage instanceof dbacontainer |
|
71
|
144 |
|
&& empty($storage->get_value()->id)) { |
|
72
|
52 |
|
$label = 'create'; |
|
73
|
|
|
} else { |
|
74
|
144 |
|
$label = "form submit: {$operation}"; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
148 |
|
$view->vars['button-labels'][$key] = $label; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* {@inheritdoc} |
|
83
|
|
|
*/ |
|
84
|
148 |
|
public function getBlockPrefix() |
|
85
|
|
|
{ |
|
86
|
148 |
|
return 'toolbar'; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|