|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Alpixel\Bundle\CMSBundle\Helper; |
|
4
|
|
|
|
|
5
|
|
|
use Alpixel\Bundle\CMSBundle\Entity\Node; |
|
6
|
|
|
use Alpixel\Bundle\CMSBundle\Entity\NodeInterface; |
|
7
|
|
|
use Doctrine\ORM\EntityManager; |
|
8
|
|
|
|
|
9
|
|
|
class CMSHelper |
|
10
|
|
|
{ |
|
11
|
|
|
protected $entityManager; |
|
12
|
|
|
protected $contentTypes; |
|
13
|
|
|
|
|
14
|
|
|
public function __construct(EntityManager $entityManager, $contentTypes) |
|
15
|
|
|
{ |
|
16
|
|
|
$this->entityManager = $entityManager; |
|
17
|
|
|
$this->contentTypes = $contentTypes; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function nodeGetTranslation(NodeInterface $node, $locale) |
|
21
|
|
|
{ |
|
22
|
|
|
$node = $this->entityManager |
|
23
|
|
|
->getRepository('CMSBundle:Node') |
|
24
|
|
|
->findTranslation($node->getNode(), $locale); |
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
return $node; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function createTranslation(Node $object, $locale) |
|
30
|
|
|
{ |
|
31
|
|
|
if ($object->getTranslationSource() !== null) { |
|
32
|
|
|
$source = $object->getTranslationSource(); |
|
33
|
|
|
} else { |
|
34
|
|
|
$source = $object; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
$content = $this->getNodeElementEntityFromNode($object); |
|
38
|
|
|
$translatedContent = clone $content; |
|
39
|
|
|
|
|
40
|
|
|
$node = $translatedContent->getNode(); |
|
41
|
|
|
$node->setLocale($locale); |
|
42
|
|
|
$node->setTranslationSource($source); |
|
43
|
|
|
$node->setTitle(sprintf('Version %s de la page "%s"', strtoupper($locale), $node->getTitle())); |
|
44
|
|
|
|
|
45
|
|
|
return $translatedContent; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getNodeElementEntityFromNode(Node $node) |
|
49
|
|
|
{ |
|
50
|
|
|
if (array_key_exists($node->getType(), $this->contentTypes)) { |
|
51
|
|
|
$contentType = $this->contentTypes[$node->getType()]; |
|
52
|
|
|
|
|
53
|
|
|
return $this->entityManager |
|
54
|
|
|
->getRepository($contentType['class']) |
|
55
|
|
|
->findOneByNode($node); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
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.