1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sonata Project package. |
5
|
|
|
* |
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sonata\TranslationBundle\Admin\Extension\Gedmo; |
13
|
|
|
|
14
|
|
|
use Gedmo\Translatable\TranslatableListener; |
15
|
|
|
use Sonata\AdminBundle\Admin\AdminInterface; |
16
|
|
|
use Sonata\TranslationBundle\Admin\Extension\AbstractTranslatableAdminExtension; |
17
|
|
|
use Sonata\TranslationBundle\Checker\TranslatableChecker; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Nicolas Bastien <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class TranslatableAdminExtension extends AbstractTranslatableAdminExtension |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var TranslatableListener |
26
|
|
|
*/ |
27
|
|
|
protected $translatableListener; |
28
|
|
|
|
29
|
|
|
public function __construct(TranslatableChecker $translatableChecker, TranslatableListener $translatableListener = null) |
30
|
|
|
{ |
31
|
|
|
parent::__construct($translatableChecker); |
32
|
|
|
$this->translatableListener = $translatableListener; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param AdminInterface $admin Deprecated, set TranslatableListener in the constructor instead. |
37
|
|
|
* |
38
|
|
|
* @return TranslatableListener |
39
|
|
|
*/ |
40
|
|
|
protected function getTranslatableListener(AdminInterface $admin) |
41
|
|
|
{ |
42
|
|
|
if (null === $this->translatableListener) { |
43
|
|
|
$this->translatableListener = $this->getContainer($admin)->get( |
44
|
|
|
'stof_doctrine_extensions.listener.translatable' |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return $this->translatableListener; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
public function alterObject(AdminInterface $admin, $object) |
55
|
|
|
{ |
56
|
|
|
if ($this->getTranslatableChecker()->isTranslatable($object)) { |
57
|
|
|
$translatableListener = $this->getTranslatableListener($admin); |
58
|
|
|
$translatableListener->setTranslatableLocale($this->getTranslatableLocale($admin)); |
59
|
|
|
$translatableListener->setTranslationFallback(''); |
|
|
|
|
60
|
|
|
|
61
|
|
|
$this->getContainer($admin)->get('doctrine')->getManager()->refresh($object); |
62
|
|
|
$object->setLocale($this->getTranslatableLocale($admin)); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
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: