From 55e24cc85feb47672722513af665ee10e5d14293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= Date: Wed, 14 Feb 2018 12:49:08 +0100 Subject: [PATCH 1/2] EZEE-1851: shell.html.twig should be rendered with language based on Accept-Language header value (#947) --- Controller/PlatformUIController.php | 13 +++++++++++-- Resources/config/services.yml | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Controller/PlatformUIController.php b/Controller/PlatformUIController.php index 8dfcc4405..0e0399f5d 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,19 +26,27 @@ class PlatformUIController extends Controller /** @var \EzSystems\PlatformUIBundle\Loader\Loader */ private $loader; - public function __construct(Provider $configAggregator, Loader $loader) + /** @var \Symfony\Component\Translation\TranslatorInterface */ + private $translator; + + public function __construct(Provider $configAggregator, Loader $loader, TranslatorInterface $translator) { $this->configAggregator = $configAggregator; $this->loader = $loader; + $this->translator = $translator; } /** * 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 35426f97c..8f130febe 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -58,6 +58,7 @@ services: arguments: - "@ezsystems.platformui.application_config.aggregator" - "@ezsystems.platformui.loader.combo_loader" + - "@translator" parent: ezsystems.platformui.controller.base ezsystems.platformui.application_config.aggregator: From e086652129be7703521ce10144e1b3f2ce136afa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20DIOT?= Date: Thu, 15 Feb 2018 08:46:10 +0100 Subject: [PATCH 2/2] Allows user to edit directly in the language displayed (#946) --- .../public/js/extensions/ez-draftconflict.js | 5 +++-- .../services/ez-locationviewviewservice.js | 3 ++- .../assets/ez-locationviewviewservice-tests.js | 17 +++++------------ 3 files changed, 10 insertions(+), 15 deletions(-) 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'); },