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\Phpcr; |
13
|
|
|
|
14
|
|
|
use Doctrine\ODM\PHPCR\DocumentManager; |
15
|
|
|
use Sonata\AdminBundle\Admin\AdminInterface; |
16
|
|
|
use Sonata\TranslationBundle\Admin\Extension\AbstractTranslatableAdminExtension; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Nicolas Bastien <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class TranslatableAdminExtension extends AbstractTranslatableAdminExtension |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @param AdminInterface $admin |
25
|
|
|
* |
26
|
|
|
* @return DocumentManager |
27
|
|
|
*/ |
28
|
|
|
protected function getDocumentManager(AdminInterface $admin) |
29
|
|
|
{ |
30
|
|
|
return $admin->getModelManager()->getDocumentManager(); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
public function alterObject(AdminInterface $admin, $object) |
37
|
|
|
{ |
38
|
|
|
$locale = $this->getTranslatableLocale($admin); |
39
|
|
|
$documentManager = $this->getDocumentManager($admin); |
40
|
|
|
$unitOfWork = $documentManager->getUnitOfWork(); |
41
|
|
|
|
42
|
|
|
if ( |
43
|
|
|
$this->getTranslatableChecker()->isTranslatable($object) |
44
|
|
|
&& ($unitOfWork->getCurrentLocale($object) !== $locale) |
45
|
|
|
) { |
46
|
|
|
$object = $this->getDocumentManager($admin)->findTranslation($admin->getClass(), $object->getId(), $locale); |
47
|
|
|
|
48
|
|
|
// if the translation did not yet exists, the locale will be |
49
|
|
|
// the fallback locale. This makes sure the new locale is set. |
50
|
|
|
if ($unitOfWork->getCurrentLocale($object) !== $locale) { |
51
|
|
|
$documentManager->bindTranslation($object, $locale); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.