Completed
Push — master ( ce31c6...fb3edb )
by David
06:25 queued 03:31
created

TranslatableAdminExtension::preUpdate()   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
        if ($this->getTranslatableChecker()->isTranslatable($object)) {
28
            $object->setLocale($this->getTranslatableLocale($admin));
29
        }
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function alterObject(AdminInterface $admin, $object)
36
    {
37
        if ($this->getTranslatableChecker()->isTranslatable($object)) {
38
            $object->setLocale($this->getTranslatableLocale($admin));
39
        }
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function preUpdate(AdminInterface $admin, $object)
46
    {
47
        $object->mergeNewTranslations();
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function prePersist(AdminInterface $admin, $object)
54
    {
55
        $object->mergeNewTranslations();
56
    }
57
}
58