1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ItBlaster\TranslationBundle\Admin; |
4
|
|
|
|
5
|
|
|
use Sonata\AdminBundle\Admin\Admin; |
6
|
|
|
use Sonata\AdminBundle\Datagrid\ListMapper; |
7
|
|
|
use Sonata\AdminBundle\Form\FormMapper; |
8
|
|
|
use Sonata\AdminBundle\Route\RouteCollection; |
9
|
|
|
use Symfony\Bridge\Propel1\Form\Type\TranslationCollectionType; |
10
|
|
|
use Symfony\Bridge\Propel1\Form\Type\TranslationType; |
11
|
|
|
|
12
|
|
|
class TranslationAdmin extends Admin |
13
|
|
|
{ |
14
|
|
|
protected $datagridValues = array( |
15
|
|
|
'_page' => 1, |
16
|
|
|
'_per_page' => 1000, |
17
|
|
|
); |
18
|
|
|
protected $perPageOptions = array(1000, 2000); |
19
|
|
|
protected $maxPerPage = 1000; |
20
|
|
|
protected $maxPageLinks = 1000; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param ListMapper $listMapper |
24
|
|
|
*/ |
25
|
|
|
protected function configureListFields(ListMapper $listMapper) |
26
|
|
|
{ |
27
|
|
|
$listMapper->add('aliasShort', null, array( |
28
|
|
|
'sortable' => false |
29
|
|
|
)); |
30
|
|
|
foreach ($this->getConfigurationPool()->getContainer()->getParameter('it_blaster_translation.locales') as $locale) { |
31
|
|
|
$listMapper->add('title'.$locale, null, array( |
32
|
|
|
'label' => $locale, |
33
|
|
|
'sortable' => false, |
34
|
|
|
'editable' => true, |
35
|
|
|
)); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$listMapper->add('_action', 'actions', array( |
39
|
|
|
'label' => 'Редактирование', |
40
|
|
|
'actions' => array( |
41
|
|
|
'edit' => array(), |
42
|
|
|
'delete' => array(), |
43
|
|
|
) |
44
|
|
|
)) |
45
|
|
|
; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param FormMapper $formMapper |
50
|
|
|
*/ |
51
|
|
|
protected function configureFormFields(FormMapper $formMapper) |
52
|
|
|
{ |
53
|
|
|
$formMapper |
54
|
|
|
->add('Alias', null, array( |
55
|
|
|
'attr' => array( |
56
|
|
|
'maxlength' => 255 |
57
|
|
|
) |
58
|
|
|
)) |
59
|
|
|
->add('TranslationI18ns', new TranslationCollectionType(), array( |
|
|
|
|
60
|
|
|
'label' => FALSE, |
61
|
|
|
'required' => FALSE, |
62
|
|
|
'type' => new TranslationType(), |
63
|
|
|
'languages' => $this->getConfigurationPool()->getContainer()->getParameter('locales'), |
64
|
|
|
'options' => array( |
65
|
|
|
'label' => FALSE, |
66
|
|
|
'data_class' => 'ItBlaster\TranslationBundle\Model\TranslationI18n', |
67
|
|
|
'columns' => array( |
68
|
|
|
'title' => array( |
69
|
|
|
'label' => "Заголовок", |
70
|
|
|
'type' => 'textarea', |
71
|
|
|
'required' => TRUE, |
72
|
|
|
'options' => array( |
73
|
|
|
'attr' => array( |
74
|
|
|
'maxlength' => 255 |
75
|
|
|
) |
76
|
|
|
) |
77
|
|
|
), |
78
|
|
|
), |
79
|
|
|
'attr' => array( |
80
|
|
|
'class' => 'block_form' |
81
|
|
|
) |
82
|
|
|
) |
83
|
|
|
)) |
84
|
|
|
; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param RouteCollection $collection |
89
|
|
|
*/ |
90
|
|
|
protected function configureRoutes(RouteCollection $collection) |
91
|
|
|
{ |
92
|
|
|
$collection |
93
|
|
|
->remove('export') |
94
|
|
|
; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param mixed $object |
99
|
|
|
* @return mixed|void |
100
|
|
|
*/ |
101
|
|
|
public function postPersist($object) |
102
|
|
|
{ |
103
|
|
|
$this->ClearCache(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param mixed $object |
108
|
|
|
* @return mixed|void |
109
|
|
|
*/ |
110
|
|
|
public function postUpdate($object) |
111
|
|
|
{ |
112
|
|
|
$this->ClearCache(); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Чистим кэш |
117
|
|
|
*/ |
118
|
|
|
protected function ClearCache() |
119
|
|
|
{ |
120
|
|
|
$app_dir = $this->getConfigurationPool()->getContainer()->get('kernel')->getRootDir(); |
121
|
|
|
$cache_dirs = array( |
122
|
|
|
'dev' => $app_dir.'/cache/dev/translations/', |
123
|
|
|
'prod' => $app_dir.'/cache/prod/translations/', |
124
|
|
|
); |
125
|
|
|
foreach($cache_dirs as $cache_dir) { |
126
|
|
|
if (is_dir($cache_dir)) { |
127
|
|
|
$files = glob($cache_dir."*.*"); |
128
|
|
|
if (count($files)) { |
129
|
|
|
foreach ($files as $file) { |
130
|
|
|
unlink($file); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
} |
138
|
|
|
|
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: