1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace FSi\FixturesBundle\Admin; |
4
|
|
|
|
5
|
|
|
use FSi\Bundle\AdminBundle\Doctrine\Admin\DependentCRUDElement; |
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 CategoryNews extends DependentCRUDElement |
14
|
|
|
{ |
15
|
|
|
public function getId() |
16
|
|
|
{ |
17
|
|
|
return 'category_news'; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function getParentId() |
21
|
|
|
{ |
22
|
|
|
return 'category'; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function getClassName() |
26
|
|
|
{ |
27
|
|
|
return 'FSi\FixturesBundle\Entity\News'; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
protected function initDataGrid(DataGridFactoryInterface $factory) |
31
|
|
|
{ |
32
|
|
|
/* @var $datagrid \FSi\Component\DataGrid\DataGrid */ |
33
|
|
|
$datagrid = $factory->createDataGrid('category_news'); |
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_crud_edit", |
43
|
|
|
'additional_parameters' => ['element' => $datagrid->getName()], |
44
|
|
|
'parameters_field_mapping' => ['id' => 'id'] |
45
|
|
|
], |
46
|
|
|
'display' => [ |
47
|
|
|
'element' => CategoryNewsDisplay::ID |
48
|
|
|
] |
49
|
|
|
] |
50
|
|
|
]); |
51
|
|
|
|
52
|
|
|
return $datagrid; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
protected function initDataSource(DataSourceFactoryInterface $factory) |
56
|
|
|
{ |
57
|
|
|
$queryBuilder = $this->getRepository() |
58
|
|
|
->createQueryBuilder('n'); |
59
|
|
|
|
60
|
|
|
if ($this->getParentObject()) { |
61
|
|
|
$queryBuilder->where(':category MEMBER OF n.categories') |
62
|
|
|
->setParameter('category', $this->getParentObject()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/* @var $datasource \FSi\Component\DataSource\DataSource */ |
66
|
|
|
$datasource = $factory->createDataSource('doctrine', ['qb' => $queryBuilder], 'category_news'); |
67
|
|
|
|
68
|
|
|
NewsDataSourceBuilder::buildNewsDataSource($datasource); |
69
|
|
|
|
70
|
|
|
return $datasource; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
protected function initForm(FormFactoryInterface $factory, $data = null) |
74
|
|
|
{ |
75
|
|
|
if ($data === null) { |
76
|
|
|
$data = new \FSi\FixturesBundle\Entity\News(); |
77
|
|
|
$data->addCategory($this->getParentObject()); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return $factory->createNamed('news', new NewsType(), $data); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: