Completed
Pull Request — master (#304)
by Piotr
07:23
created

CustomNews   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 7
dl 0
loc 42
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 CustomNews extends CRUDElement
12
{
13
    public function getId()
14
    {
15
        return 'custom_news';
16
    }
17
18
    public function getClassName()
19
    {
20
        return 'FSi\FixturesBundle\Entity\News';
21
    }
22
23
    protected function initDataGrid(DataGridFactoryInterface $factory)
24
    {
25
        /* @var $datagrid \FSi\Component\DataGrid\DataGrid */
26
        $datagrid = $factory->createDataGrid('custom_news');
27
28
        return $datagrid;
29
    }
30
31
    protected function initDataSource(DataSourceFactoryInterface $factory)
32
    {
33
        /* @var $datasource \FSi\Component\DataSource\DataSource */
34
        $datasource = $factory->createDataSource('doctrine', ['entity' => $this->getClassName()], 'custom_news');
35
36
        $datasource->addField('title', 'text', 'eq', ['form_filter' => false]);
37
38
        return $datasource;
39
    }
40
41
    protected function initForm(FormFactoryInterface $factory, $data = null)
42
    {
43
        $builder = $factory->createNamedBuilder(
44
            'news',
45
            TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\FormType', 'form'),
46
            $data,
47
            ['data_class' => $this->getClassName()]
48
        );
49
50
        return $builder->getForm();
51
    }
52
}
53