Completed
Pull Request — 2.1 (#242)
by Łukasz
08:11 queued 05:17
created

News::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace FSi\FixturesBundle\Admin;
4
5
use FSi\Bundle\AdminBundle\Doctrine\Admin\CRUDElement;
6
use FSi\Component\DataGrid\DataGridFactoryInterface;
7
use FSi\Component\DataSource\DataSourceFactoryInterface;
8
use FSi\FixturesBundle\DataGrid\NewsDataGridBuilder;
9
use FSi\FixturesBundle\DataSource\NewsDataSourceBuilder;
10
use FSi\FixturesBundle\Form\NewsType;
11
use Symfony\Component\Form\FormFactoryInterface;
12
13
class News extends CRUDElement
14
{
15
    public function getId()
16
    {
17
        return 'news';
18
    }
19
20
    public function getClassName()
21
    {
22
        return 'FSi\FixturesBundle\Entity\News';
23
    }
24
25
    protected function initDataGrid(DataGridFactoryInterface $factory)
26
    {
27
        /* @var $datagrid \FSi\Component\DataGrid\DataGrid */
28
        $datagrid = $factory->createDataGrid('news');
29
30
        NewsDataGridBuilder::buildNewsDataGrid($datagrid);
31
32
        $datagrid->addColumn('actions', 'action', [
33
            'label' => 'admin.news.list.actions',
34
            'field_mapping' => ['id'],
35
            'actions' => [
36
                'edit' => [
37
                    'route_name' => "fsi_admin_crud_edit",
38
                    'additional_parameters' => ['element' => $datagrid->getName()],
39
                    'parameters_field_mapping' => ['id' => 'id']
40
                ],
41
                'display' => [
42
                    'element' => DisplayNews::ID
43
                ]
44
            ]
45
        ]);
46
47
        return $datagrid;
48
    }
49
50
    protected function initDataSource(DataSourceFactoryInterface $factory)
51
    {
52
        /* @var $datasource \FSi\Component\DataSource\DataSource */
53
        $datasource = $factory->createDataSource('doctrine', ['entity' => $this->getClassName()], 'news');
54
55
        NewsDataSourceBuilder::buildNewsDataSource($datasource);
56
57
        return $datasource;
58
    }
59
60
    protected function initForm(FormFactoryInterface $factory, $data = null)
61
    {
62
        return $factory->createNamed('news', new NewsType(), $data);
63
    }
64
}
65