Passed
Push — master ( 8d0e91...227e03 )
by Artem
47s queued 15s
created

AbstractTranslateAdmin::removeNullTranslate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
namespace Stfalcon\Bundle\EventBundle\Admin\AbstractClass;
4
5
use A2lix\TranslationFormBundle\Util\GedmoTranslatable;
6
use Sonata\AdminBundle\Admin\Admin;
7
8
/**
9
 * AbstractTranslateAdmin.
10
 */
11
class AbstractTranslateAdmin extends Admin
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    public function preUpdate($object)
17
    {
18
        $this->removeNullTranslate($object);
19
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function prePersist($object)
25
    {
26
        $this->removeNullTranslate($object);
27
    }
28
29
    /**
30
     * @param GedmoTranslatable $object
31
     */
32
    public function removeNullTranslate($object)
33
    {
34
        foreach ($object->getTranslations() as $key => $translation) {
35
            if (!$translation->getContent()) {
36
                $object->getTranslations()->removeElement($translation);
37
            }
38
        }
39
    }
40
}
41