Passed
Push — up-php7 ( a2fe11...4e1c1e )
by Erik
05:48
created

StaticReferenceAdmin::prePersist()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * @author    Gerard van Helden <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
7
namespace Zicht\Bundle\UrlBundle\Admin;
8
9
use Sonata\AdminBundle\Datagrid\ListMapper;
10
use Sonata\AdminBundle\Show\ShowMapper;
11
use Sonata\AdminBundle\Admin\Admin;
12
use Sonata\AdminBundle\Form\FormMapper;
13
14
/**
15
 * Admin implementation for static references
16
 *
17
 */
18
class StaticReferenceAdmin extends Admin
0 ignored issues
show
Deprecated Code introduced by
The class Sonata\AdminBundle\Admin\Admin has been deprecated: since version 3.1, to be removed in 4.0. Use Sonata\AdminBundle\AbstractAdmin instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

18
class StaticReferenceAdmin extends /** @scrutinizer ignore-deprecated */ Admin
Loading history...
19
{
20
    /**
21
     * @{inheritDoc}
22
     */
23
    public function configureListFields(ListMapper $listMapper)
24
    {
25
        $listMapper
26
            ->add('machine_name')
27
            ->add(
28
                '_action',
29
                'actions',
30
                array(
31
                    'actions' => array(
32
                        'show'   => array(),
33
                        'edit'   => array(),
34
                        'delete' => array()
35
                    )
36
                )
37
            );
38
    }
39
40
    /**
41
     * @{inheritDoc}
42
     */
43
    protected function configureFormFields(FormMapper $form)
44
    {
45
        if ($this->getSubject()->getId()) {
46
            $form
47
                ->add('machine_name')
48
                ->add(
49
                    'translations',
50
                    'sonata_type_collection',
51
                    array(),
52
                    array(
53
                        'edit'   => 'inline',
54
                        'inline' => 'table',
55
                    )
56
                );
57
        } else {
58
            $form
59
                ->add('machine_name');
60
        }
61
    }
62
63
    /**
64
     * @{inheritDoc}
65
     */
66
    protected function configureShowFields(ShowMapper $show)
67
    {
68
        $show
69
            ->add('machine_name')
70
            ->add('url');
71
    }
72
73
    /**
74
     * @{inheritDoc}
75
     */
76
    public function prePersist($object)
77
    {
78
        $object->addMissingTranslations();
79
    }
80
81
    /**
82
     * @{inheritDoc}
83
     */
84
    public function preUpdate($object)
85
    {
86
        $object->addMissingTranslations();
87
    }
88
}
89