Completed
Pull Request — 3.1 (#348)
by Piotr
29:38 queued 15:17
created

News   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 7
dl 0
loc 56
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 4 1
A getClassName() 0 4 1
A initDataGrid() 0 21 1
A initDataSource() 0 12 1
A initForm() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FSi\FixturesBundle\Admin;
6
7
use FSi\Bundle\AdminBundle\Doctrine\Admin\CRUDElement;
8
use FSi\Component\DataGrid\DataGridFactoryInterface;
9
use FSi\Component\DataGrid\DataGridInterface;
10
use FSi\Component\DataSource\DataSourceFactoryInterface;
11
use FSi\Component\DataSource\DataSourceInterface;
12
use FSi\FixturesBundle\DataGrid\NewsDataGridBuilder;
13
use FSi\FixturesBundle\DataSource\NewsDataSourceBuilder;
14
use FSi\FixturesBundle\Entity;
15
use FSi\FixturesBundle\Form\NewsType;
16
use Symfony\Component\Form\FormFactoryInterface;
17
use Symfony\Component\Form\FormInterface;
18
19
class News extends CRUDElement
20
{
21
    public function getId(): string
22
    {
23
        return 'news';
24
    }
25
26
    public function getClassName(): string
27
    {
28
        return Entity\News::class;
29
    }
30
31
    protected function initDataGrid(DataGridFactoryInterface $factory): DataGridInterface
32
    {
33
        $datagrid = $factory->createDataGrid($this->getId());
34
35
        NewsDataGridBuilder::buildNewsDataGrid($datagrid);
36
37
        $datagrid->addColumn('actions', 'action', [
38
            'label' => 'admin.news.list.actions',
39
            'field_mapping' => ['id'],
40
            'actions' => [
41
                'edit' => [
42
                    'route_name' => 'fsi_admin_form',
43
                    'additional_parameters' => ['element' => $datagrid->getName()],
44
                    'parameters_field_mapping' => ['id' => 'id']
45
                ],
46
                'display' => ['element' => DisplayNews::ID]
47
            ]
48
        ]);
49
50
        return $datagrid;
51
    }
52
53
    protected function initDataSource(DataSourceFactoryInterface $factory): DataSourceInterface
54
    {
55
        $datasource = $factory->createDataSource(
56
            'doctrine-orm',
57
            ['entity' => $this->getClassName()],
58
            $this->getId()
59
        );
60
61
        NewsDataSourceBuilder::buildNewsDataSource($datasource);
62
63
        return $datasource;
64
    }
65
66
    protected function initForm(FormFactoryInterface $factory, $data = null): FormInterface
67
    {
68
        return $factory->createNamed(
69
            'news',
70
            NewsType::class,
71
            $data
72
        );
73
    }
74
}
75