Completed
Pull Request — master (#144)
by
unknown
12:31
created

CustomerAdmin::configureFormFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 14
rs 9.4285
1
<?php
2
3
namespace AppBundle\Admin;
4
5
use AppBundle\Entity\Customer;
6
use Sonata\AdminBundle\Admin\Admin;
7
use Sonata\AdminBundle\Datagrid\ListMapper;
8
use Sonata\AdminBundle\Datagrid\DatagridMapper;
9
use Sonata\AdminBundle\Form\FormMapper;
10
11
class CustomerAdmin extends Admin
12
{
13
    protected $baseRouteName = 'AppBundle\Entity\Customer';
14
    protected $baseRoutePattern = 'Customer';
15
    protected $datagridValues = [
16
        '_sort_order' => 'DESC',
17
        '_sort_by' => 'id',
18
    ];
19
20
    /**
21
     * @param \Sonata\AdminBundle\Form\FormMapper $formMapper
22
     */
23
    protected function configureFormFields(FormMapper $formMapper)
24
    {
25
        $formMapper
26
            ->with('Customer', ['class' => 'col-lg-12'])
27
            ->add('firstName')
28
            ->add('lastName')
29
            ->add('email')
30
            ->add('facebookId')
31
            //->add('apiKey')
32
            ->add('apiKey', 'text', ['attr' => ['readonly' => true]])
33
            ->add('orders')
34
            ->end()
35
        ;
36
    }
37
38
    /**
39
     * @param \Sonata\AdminBundle\Datagrid\ListMapper $listMapper
40
     */
41
    protected function configureListFields(ListMapper $listMapper)
42
    {
43
        $listMapper
44
            ->add('email')
45
            ->add('apiKey')
46
            ->add('_action', 'actions', [
47
                'actions' => [
48
                    'edit' => [],
49
                    'delete' => [],
50
                ],
51
            ])
52
        ;
53
    }
54
55
    /**
56
     * @param \Sonata\AdminBundle\Datagrid\DatagridMapper $datagridMapper
57
     */
58
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
59
    {
60
        $datagridMapper
61
            ->add('email')
62
        ;
63
    }
64
65
    public function toString($object)
66
    {
67
        return $object instanceof Customer
68
            ? $object->getEmail()
69
            : 'Customer'; // shown in the breadcrumb on the create views
70
    }
71
}
72