1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sonata 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) |
30
|
|
|
{ |
31
|
|
|
parent::__construct($translatableChecker); |
32
|
|
|
$this->translatableListener = $translatableListener; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param AdminInterface $admin |
|
|
|
|
37
|
|
|
* |
38
|
|
|
* @return TranslatableListener |
39
|
|
|
*/ |
40
|
|
|
protected function getTranslatableListener() |
41
|
|
|
{ |
42
|
|
|
return $this->translatableListener; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
|
|
public function alterObject(AdminInterface $admin, $object) |
49
|
|
|
{ |
50
|
|
|
if ($this->getTranslatableChecker()->isTranslatable($object)) { |
51
|
|
|
$this->getTranslatableListener()->setTranslatableLocale($this->getTranslatableLocale($admin)); |
52
|
|
|
$this->getTranslatableListener()->setTranslationFallback(''); |
|
|
|
|
53
|
|
|
|
54
|
|
|
$this->getContainer($admin)->get('doctrine')->getManager()->refresh($object); |
55
|
|
|
$object->setLocale($this->getTranslatableLocale($admin)); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.