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
|
|
|
parent::__construct($translatableChecker); |
31
|
|
|
$this->translatableListener = $translatableListener; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param AdminInterface $admin |
|
|
|
|
36
|
|
|
* |
37
|
|
|
* @return TranslatableListener |
38
|
|
|
*/ |
39
|
|
|
protected function getTranslatableListener() |
40
|
|
|
{ |
41
|
|
|
return $this->translatableListener; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
|
|
public function alterObject(AdminInterface $admin, $object) |
48
|
|
|
{ |
49
|
|
|
if ($this->getTranslatableChecker()->isTranslatable($object)) { |
50
|
|
|
$this->getTranslatableListener()->setTranslatableLocale($this->getTranslatableLocale($admin)); |
51
|
|
|
$this->getTranslatableListener()->setTranslationFallback(''); |
|
|
|
|
52
|
|
|
|
53
|
|
|
$this->getContainer($admin)->get('doctrine')->getManager()->refresh($object); |
54
|
|
|
$object->setLocale($this->getTranslatableLocale($admin)); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
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.