Completed
Pull Request — master (#26)
by
unknown
03:56
created

TranslatableAdminExtension::prePersist()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
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\Knplabs;
13
14
use Sonata\AdminBundle\Admin\AdminInterface;
15
use Sonata\TranslationBundle\Admin\Extension\AbstractTranslatableAdminExtension;
16
17
/**
18
 * @author Alfonso Machado <[email protected]>
19
 */
20
class TranslatableAdminExtension extends AbstractTranslatableAdminExtension
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function alterNewInstance(AdminInterface $admin, $object)
26
    {
27
        $object->setLocale($this->getTranslatableLocale($admin));
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function alterObject(AdminInterface $admin, $object)
34
    {
35
        if ($this->getTranslatableChecker()->isTranslatable($object)) {
36
            $object->setLocale($this->getTranslatableLocale($admin));
37
        }
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function preUpdate(AdminInterface $admin, $object)
44
    {
45
        $object->mergeNewTranslations();
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function prePersist(AdminInterface $admin, $object)
52
    {
53
        $object->mergeNewTranslations();
54
    }
55
}
56