TranslatableAdminExtension::alterObject()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\TranslationBundle\Admin\Extension\Knplabs;
15
16
use Sonata\AdminBundle\Admin\AdminInterface;
17
use Sonata\TranslationBundle\Admin\Extension\AbstractTranslatableAdminExtension;
18
19
/**
20
 * @author Alfonso Machado <[email protected]>
21
 */
22
class TranslatableAdminExtension extends AbstractTranslatableAdminExtension
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function alterNewInstance(AdminInterface $admin, $object): void
28
    {
29
        if ($this->getTranslatableChecker()->isTranslatable($object)) {
30
            $object->setLocale($this->getTranslatableLocale($admin));
31
        }
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function alterObject(AdminInterface $admin, $object): void
38
    {
39
        if ($this->getTranslatableChecker()->isTranslatable($object)) {
40
            $object->setLocale($this->getTranslatableLocale($admin));
41
        }
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function preUpdate(AdminInterface $admin, $object): void
48
    {
49
        $object->mergeNewTranslations();
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function prePersist(AdminInterface $admin, $object): void
56
    {
57
        $object->mergeNewTranslations();
58
    }
59
}
60