diff --git a/Controller/PlatformUIController.php b/Controller/PlatformUIController.php index 8f9bbf1f6..2f93a4eac 100644 --- a/Controller/PlatformUIController.php +++ b/Controller/PlatformUIController.php @@ -16,6 +16,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Symfony\Component\Translation\TranslatorInterface; class PlatformUIController extends Controller { @@ -25,23 +26,31 @@ class PlatformUIController extends Controller /** @var \EzSystems\PlatformUIBundle\Loader\Loader */ private $loader; + /** @var \Symfony\Component\Translation\TranslatorInterface */ + private $translator; + /** @var int */ private $comboCacheTtl; - public function __construct(Provider $configAggregator, Loader $loader, $comboCacheTtl = 0) + public function __construct(Provider $configAggregator, Loader $loader, TranslatorInterface $translator, $comboCacheTtl = 0) { $this->configAggregator = $configAggregator; $this->loader = $loader; + $this->translator = $translator; $this->comboCacheTtl = $comboCacheTtl; } /** * Renders the "shell" page to run the JavaScript application. * + * @param \Symfony\Component\HttpFoundation\Request $request + * * @return \Symfony\Component\HttpFoundation\Response */ - public function shellAction() + public function shellAction(Request $request) { + $this->translator->setLocale($request->getPreferredLanguage() ?: $request->getDefaultLocale()); + return $this->render( 'eZPlatformUIBundle:PlatformUI:shell.html.twig', ['parameters' => $this->configAggregator->getConfig()] diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 1aaf5afd1..797c64e6f 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -59,6 +59,7 @@ services: arguments: - "@ezsystems.platformui.application_config.aggregator" - "@ezsystems.platformui.loader.combo_loader" + - "@translator" - "@=container.getParameter('kernel.debug') ? 0 : parameter('ezsystems.platformui.application_config.combo_loader.cache_ttl')" parent: ezsystems.platformui.controller.base diff --git a/Resources/public/js/extensions/ez-draftconflict.js b/Resources/public/js/extensions/ez-draftconflict.js index 065be8487..127e9c989 100644 --- a/Resources/public/js/extensions/ez-draftconflict.js +++ b/Resources/public/js/extensions/ez-draftconflict.js @@ -28,16 +28,17 @@ YUI.add('ez-draftconflict', function (Y) { * @method _fireEditContentRequest * @param {Y.eZ.ContentInfo} contentItem * @param {Y.eZ.ContentType} contentType + * @param {String} languageCode * @protected */ - _fireEditContentRequest: function(contentInfo, contentType) { + _fireEditContentRequest: function(contentInfo, contentType, languageCode) { /** * Fired when a content needs to be edited * @event editContentRequest */ this.fire('editContentRequest',{ contentInfo: contentInfo, - languageCode: contentInfo.get('mainLanguageCode'), + languageCode: languageCode ? languageCode : contentInfo.get('mainLanguageCode'), contentType: contentType }); }, diff --git a/Resources/public/js/views/services/ez-locationviewviewservice.js b/Resources/public/js/views/services/ez-locationviewviewservice.js index b42ad329e..a0c95cd59 100644 --- a/Resources/public/js/views/services/ez-locationviewviewservice.js +++ b/Resources/public/js/views/services/ez-locationviewviewservice.js @@ -68,7 +68,8 @@ YUI.add('ez-locationviewviewservice', function (Y) { _editContent: function (e) { this._fireEditContentRequest( this.get('location').get('contentInfo'), - this.get('contentType') + this.get('contentType'), + this.get('languageCode') ); }, diff --git a/Tests/js/views/services/assets/ez-locationviewviewservice-tests.js b/Tests/js/views/services/assets/ez-locationviewviewservice-tests.js index f8eed6fce..200873bec 100644 --- a/Tests/js/views/services/assets/ez-locationviewviewservice-tests.js +++ b/Tests/js/views/services/assets/ez-locationviewviewservice-tests.js @@ -313,16 +313,9 @@ YUI.add('ez-locationviewviewservice-tests', function (Y) { }, "Should fire `editContentRequest` when receiving an editAction event": function () { - var languageCode = "fre-FR", - contentInfo = new Mock(), + var contentInfo = new Mock(), contentType = {}; - Mock.expect(contentInfo, { - method: 'get', - args: ['mainLanguageCode'], - returns: languageCode - }); - Mock.expect(this.locationMock, { method: 'get', args: ['contentInfo'], @@ -331,7 +324,7 @@ YUI.add('ez-locationviewviewservice-tests', function (Y) { this.service.set('contentType', contentType); - this.service.on('*:editContentRequest', function (e) { + this.service.on('*:editContentRequest', Y.bind(function (e) { Assert.areSame( contentInfo, e.contentInfo, @@ -343,11 +336,11 @@ YUI.add('ez-locationviewviewservice-tests', function (Y) { "ContentType provided in the EventFacade is not the same" ); Assert.areSame( - languageCode, + this.languageCode, e.languageCode, - "LanguageCode provided in the EventFacade is not the same" + "LanguageCode provided in the EventFacade is the one of the displayed content" ); - }); + }, this)); this.service.fire('whatever:editAction'); },