Skip to content

Commit 9b4b507

Browse files
committed
Properly translate content type name with translation helper
1 parent 72eb015 commit 9b4b507

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

bundle/Controller/Admin/TreeController.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Netgen\Bundle\InformationCollectionBundle\Controller\Admin;
44

55
use eZ\Bundle\EzPublishCoreBundle\Controller;
6+
use eZ\Publish\Core\Helper\TranslationHelper;
67
use Netgen\Bundle\InformationCollectionBundle\API\Service\InformationCollection;
78
use Netgen\Bundle\InformationCollectionBundle\API\Value\InformationCollection\Content;
89
use Netgen\Bundle\InformationCollectionBundle\API\Value\InformationCollection\Query;
@@ -27,21 +28,29 @@ class TreeController extends Controller
2728
*/
2829
protected $service;
2930

31+
/**
32+
* @var \eZ\Publish\Core\Helper\TranslationHelper
33+
*/
34+
private $translationHelper;
35+
3036
/**
3137
* TreeController constructor.
3238
*
3339
* @param \Netgen\Bundle\InformationCollectionBundle\API\Service\InformationCollection
3440
* @param \Symfony\Component\Translation\TranslatorInterface $translator
3541
* @param \Symfony\Component\Routing\RouterInterface $router
42+
* @param \eZ\Publish\Core\Helper\TranslationHelper $translationHelper
3643
*/
3744
public function __construct(
3845
InformationCollection $service,
3946
TranslatorInterface $translator,
40-
RouterInterface $router
47+
RouterInterface $router,
48+
TranslationHelper $translationHelper
4149
) {
4250
$this->translator = $translator;
4351
$this->router = $router;
4452
$this->service = $service;
53+
$this->translationHelper = $translationHelper;
4554
}
4655

4756
/**
@@ -122,7 +131,7 @@ protected function getCollections(Content $content, $isRoot = false)
122131
return array(
123132
'id' => $content->content->id,
124133
'parent' => $isRoot ? '#' : '0',
125-
'text' => $content->contentType->getName($languages[0]) . ' (' . strval($count->count) . ')',
134+
'text' => $this->translationHelper->getTranslatedByMethod($content->contentType, 'getName') . ' (' . strval($count->count) . ')',
126135
'children' => false,
127136
'a_attr' => array(
128137
'href' => $this->router->generate('netgen_information_collection.route.admin.collection_list', ['contentId' => $content->content->id]),

bundle/Resources/config/admin.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ services:
3636
- "@netgen_information_collection.api.service"
3737
- "@translator"
3838
- "@router"
39+
- "@ezpublish.translation_helper"
3940

4041
netgen_information_collection.templating.admin_global_variable:
4142
class: Netgen\Bundle\InformationCollectionBundle\Templating\Twig\AdminGlobalVariable

0 commit comments

Comments
 (0)