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