Completed
Push — master ( 5a2c46...47cba7 )
by Jarek
11s
created

Category   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 8
dl 0
loc 76
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace FSi\FixturesBundle\Admin;
4
5
use FSi\Bundle\AdminBundle\Doctrine\Admin\CRUDElement;
6
use FSi\Bundle\AdminBundle\Form\TypeSolver;
7
use FSi\Component\DataGrid\DataGridFactoryInterface;
8
use FSi\Component\DataSource\DataSourceFactoryInterface;
9
use Symfony\Component\Form\FormFactoryInterface;
10
11
class Category extends CRUDElement
12
{
13
    public function getId()
14
    {
15
        return 'category';
16
    }
17
18
    public function getClassName()
19
    {
20
        return 'FSi\FixturesBundle\Entity\Category';
21
    }
22
23
    protected function initDataGrid(DataGridFactoryInterface $factory)
24
    {
25
        /* @var $datagrid \FSi\Component\DataGrid\DataGrid */
26
        $datagrid = $factory->createDataGrid('category');
27
        $datagrid->addColumn('title', 'text', [
28
            'label' => 'admin.category.list.title',
29
            'field_mapping' => ['title'],
30
            'editable' => true
31
        ]);
32
        $datagrid->addColumn('actions', 'action', [
33
            'label' => 'admin.category.list.actions',
34
            'field_mapping' => ['id'],
35
            'actions' => [
36
                'news' => [
37
                    'route_name' => "fsi_admin_crud_list",
38
                    'additional_parameters' => ['element' => 'category_news'],
39
                    'parameters_field_mapping' => ['parent' => 'id'],
40
                    'redirect_uri' => false,
41
                ],
42
                'edit' => [
43
                    'route_name' => "fsi_admin_crud_edit",
44
                    'additional_parameters' => ['element' => $this->getId()],
45
                    'parameters_field_mapping' => ['id' => 'id']
46
                ],
47
            ]
48
        ]);
49
50
        return $datagrid;
51
    }
52
53
    protected function initDataSource(DataSourceFactoryInterface $factory)
54
    {
55
        /* @var $datasource \FSi\Component\DataSource\DataSource */
56
        $datasource = $factory->createDataSource('doctrine', ['entity' => $this->getClassName()], 'news');
57
        $datasource->addField('title', 'text', 'like', [
58
            'sortable' => false,
59
            'form_options' => [
60
                'label' => 'admin.category.list.title',
61
            ]
62
        ]);
63
64
        $datasource->setMaxResults(10);
65
66
        return $datasource;
67
    }
68
69
    protected function initForm(FormFactoryInterface $factory, $data = null)
70
    {
71
        $builder = $factory->createNamedBuilder(
72
            'category',
73
            TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\FormType', 'form'),
74
            $data,
75
            ['data_class' => $this->getClassName()]
76
        );
77
78
        $builder->add(
79
            'title',
80
            TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\TextType', 'text'),
81
            ['label' => 'admin.category.list.title']
82
        );
83
84
        return $builder->getForm();
85
    }
86
}
87