| @@ 29-54 (lines=26) @@ | ||
| 26 | ->getOneOrNullResult(); |
|
| 27 | } |
|
| 28 | ||
| 29 | public function findTranslation(Block $block, $locale) |
|
| 30 | { |
|
| 31 | $source = null; |
|
| 32 | ||
| 33 | // We are checking if the node is the translation provider or translated |
|
| 34 | // from an other node |
|
| 35 | if ($block->getTranslationSource() !== null) { |
|
| 36 | $source = $block->getTranslationSource(); |
|
| 37 | if ($source->getLocale() == $locale) { |
|
| 38 | return $source; |
|
| 39 | } |
|
| 40 | } else { |
|
| 41 | $source = $block; |
|
| 42 | } |
|
| 43 | ||
| 44 | return $this->createQueryBuilder('n') |
|
| 45 | ->addSelect('n') |
|
| 46 | ->andWhere('n.translationSource = :source') |
|
| 47 | ->andWhere('n.locale = :locale') |
|
| 48 | ->setParameters([ |
|
| 49 | 'source' => $source, |
|
| 50 | 'locale' => $locale, |
|
| 51 | ]) |
|
| 52 | ->getQuery() |
|
| 53 | ->getOneOrNullResult(); |
|
| 54 | } |
|
| 55 | } |
|
| 56 | ||
| @@ 35-60 (lines=26) @@ | ||
| 32 | ->getOneOrNullResult(); |
|
| 33 | } |
|
| 34 | ||
| 35 | public function findTranslation(Node $node, $locale) |
|
| 36 | { |
|
| 37 | $nodeSource = null; |
|
| 38 | ||
| 39 | // We are checking if the node is the translation provider or translated |
|
| 40 | // from an other node |
|
| 41 | if ($node->getTranslationSource() !== null) { |
|
| 42 | $nodeSource = $node->getTranslationSource(); |
|
| 43 | if ($nodeSource->getLocale() == $locale) { |
|
| 44 | return $nodeSource; |
|
| 45 | } |
|
| 46 | } else { |
|
| 47 | $nodeSource = $node; |
|
| 48 | } |
|
| 49 | ||
| 50 | return $this->createQueryBuilder('n') |
|
| 51 | ->addSelect('n') |
|
| 52 | ->andWhere('n.translationSource = :source') |
|
| 53 | ->andWhere('n.locale = :locale') |
|
| 54 | ->setParameters([ |
|
| 55 | 'source' => $nodeSource, |
|
| 56 | 'locale' => $locale, |
|
| 57 | ]) |
|
| 58 | ->getQuery() |
|
| 59 | ->getOneOrNullResult(); |
|
| 60 | } |
|
| 61 | } |
|
| 62 | ||