SetSaveButtonSubscriber::preSetData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
dl 6
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Black\Common\Application\Form\EventListener;
4
5
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
6
use Symfony\Component\Form\FormEvents;
7
use Symfony\Component\Form\FormEvent;
8
use Symfony\Component\Form\FormInterface;
9
10
/**
11
 * Class SetSaveButtonSubscriber
12
 *
13
 * SetSaveButtonSubscriber add "save" button for your FormType
14
 */
15 View Code Duplication
class SetSaveButtonSubscriber implements EventSubscriberInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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