@@ 15-52 (lines=38) @@ | ||
12 | * |
|
13 | * SetResetButtonSubscriber add "reset" button for your FormType |
|
14 | */ |
|
15 | class SetResetButtonSubscriber implements EventSubscriberInterface |
|
16 | { |
|
17 | /** |
|
18 | * List events for this subscriber |
|
19 | * |
|
20 | * @return array |
|
21 | */ |
|
22 | public static function getSubscribedEvents() |
|
23 | { |
|
24 | return [FormEvents::PRE_SET_DATA => 'preSetData']; |
|
25 | } |
|
26 | ||
27 | /** |
|
28 | * Pre set Data form the subscriber and add button |
|
29 | * |
|
30 | * @param FormEvent $event |
|
31 | */ |
|
32 | public function preSetData(FormEvent $event) |
|
33 | { |
|
34 | $form = $event->getForm(); |
|
35 | ||
36 | $this->addResetButton($form); |
|
37 | } |
|
38 | ||
39 | /** |
|
40 | * Add the button |
|
41 | * |
|
42 | * @param FormInterface $form |
|
43 | */ |
|
44 | private function addResetButton(FormInterface $form) |
|
45 | { |
|
46 | $form |
|
47 | ->add('reset', 'reset', [ |
|
48 | 'label' => 'black.bundle.common.eventListener.setButtonsSubscriber.button.reset.label' |
|
49 | ] |
|
50 | ); |
|
51 | } |
|
52 | } |
|
53 |
@@ 15-50 (lines=36) @@ | ||
12 | * |
|
13 | * SetSaveAndAddButtonSubscriber add "save and add" button for your FormType |
|
14 | */ |
|
15 | class SetSaveAndAddButtonSubscriber implements EventSubscriberInterface |
|
16 | { |
|
17 | /** |
|
18 | * {@inheritDoc} |
|
19 | */ |
|
20 | public static function getSubscribedEvents() |
|
21 | { |
|
22 | return [FormEvents::PRE_SET_DATA => 'preSetData']; |
|
23 | } |
|
24 | ||
25 | /** |
|
26 | * Pre set Data form the subscriber and add buttons |
|
27 | * |
|
28 | * @param FormEvent $event |
|
29 | */ |
|
30 | public function preSetData(FormEvent $event) |
|
31 | { |
|
32 | $form = $event->getForm(); |
|
33 | ||
34 | $this->addSaveAndAddButton($form); |
|
35 | } |
|
36 | ||
37 | /** |
|
38 | * Add the button |
|
39 | * |
|
40 | * @param FormInterface $form |
|
41 | */ |
|
42 | private function addSaveAndAddButton(FormInterface $form) |
|
43 | { |
|
44 | $form |
|
45 | ->add('saveAndAdd', 'submit', [ |
|
46 | 'label' => 'black.bundle.common.eventListener.setButtonsSubscriber.button.saveAndAdd.label' |
|
47 | ] |
|
48 | ); |
|
49 | } |
|
50 | } |
|
51 |
@@ 15-50 (lines=36) @@ | ||
12 | * |
|
13 | * SetSaveButtonSubscriber add "save" button for your FormType |
|
14 | */ |
|
15 | class SetSaveButtonSubscriber implements EventSubscriberInterface |
|
16 | { |
|
17 | /** |
|
18 | * {@inheritDoc} |
|
19 | */ |
|
20 | public static function getSubscribedEvents() |
|
21 | { |
|
22 | return [FormEvents::PRE_SET_DATA => 'preSetData']; |
|
23 | } |
|
24 | ||
25 | /** |
|
26 | * Pre set Data form the subscriber and add buttons |
|
27 | * |
|
28 | * @param FormEvent $event |
|
29 | */ |
|
30 | public function preSetData(FormEvent $event) |
|
31 | { |
|
32 | $form = $event->getForm(); |
|
33 | ||
34 | $this->addCreateButtons($form); |
|
35 | } |
|
36 | ||
37 | /** |
|
38 | * Add the buttons |
|
39 | * |
|
40 | * @param FormInterface $form |
|
41 | */ |
|
42 | private function addCreateButtons(FormInterface $form) |
|
43 | { |
|
44 | $form |
|
45 | ->add('save', 'submit', [ |
|
46 | 'label' => 'black.bundle.common.eventListener.setButtonsSubscriber.button.save.label' |
|
47 | ] |
|
48 | ); |
|
49 | } |
|
50 | } |
|
51 |