CategoryAdmin   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 5
dl 0
loc 35
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A toString() 0 6 2
A configureFormFields() 0 11 1
A configureDatagridFilters() 0 4 1
A configureListFields() 0 4 1
1
<?php
2
3
namespace ClientBundle\Admin;
4
5
use Sonata\AdminBundle\Admin\AbstractAdmin;
6
use Sonata\AdminBundle\Datagrid\ListMapper;
7
use Sonata\AdminBundle\Datagrid\DatagridMapper;
8
use Sonata\AdminBundle\Form\FormMapper;
9
use ClientBundle\Entity\Category;
10
11
/**
12
 * Class CategoryAdmin
13
 */
14
class CategoryAdmin extends AbstractAdmin
15
{
16
    /**
17
     * @param mixed $object
18
     * @return string
19
     */
20
    public function toString($object)
21
    {
22
        return $object instanceof Category
23
        ? $object->getName()
24
        : 'Category'; // shown in the breadcrumb on the create view
25
    }
26
27
    protected function configureFormFields(FormMapper $formMapper)
28
    {
29
        $formMapper
30
            ->add('name', 'text')
31
            ->add('clients', 'entity', [
32
                'class' => 'ClientBundle:Client',
33
                'choice_label' => 'DisplayName',
34
                'multiple' => true,
35
            ])
36
        ;
37
    }
38
39
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
40
    {
41
        $datagridMapper->add('name');
42
    }
43
44
    protected function configureListFields(ListMapper $listMapper)
45
    {
46
        $listMapper->addIdentifier('name');
47
    }
48
}
49