Completed
Pull Request — 3.1 (#347)
by Łukasz
16:49 queued 11:36
created

CustomNews   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 6
dl 0
loc 34
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 4 1
A initDataSource() 0 6 1
A initForm() 0 9 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\Entity;
13
use Symfony\Component\Form\Extension\Core\Type\FormType;
14
use Symfony\Component\Form\FormFactoryInterface;
15
use Symfony\Component\Form\FormInterface;
16
17
class CustomNews extends CRUDElement
18
{
19
    public function getId(): string
20
    {
21
        return 'custom_news';
22
    }
23
24
    public function getClassName(): string
25
    {
26
        return Entity\News::class;
27
    }
28
29
    protected function initDataGrid(DataGridFactoryInterface $factory): DataGridInterface
30
    {
31
        return $factory->createDataGrid($this->getId());
32
    }
33
34
    protected function initDataSource(DataSourceFactoryInterface $factory): DataSourceInterface
35
    {
36
        return $factory
37
            ->createDataSource('doctrine-orm', ['entity' => $this->getClassName()], $this->getId())
38
            ->addField('title', 'text', 'eq', ['form_filter' => false]);
39
    }
40
41
    protected function initForm(FormFactoryInterface $factory, $data = null): FormInterface
42
    {
43
        return $factory->createNamedBuilder(
44
            'news',
45
            FormType::class,
46
            $data,
47
            ['data_class' => $this->getClassName()]
48
        )->getForm();
49
    }
50
}
51