summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2019-10-03 10:46:58 +0200
committerGitHub <noreply@github.com>2019-10-03 10:46:58 +0200
commit8825d8c068f0a095493738b62ead9de3f6aeebd9 (patch)
treebd6b4c68fa923815817a7a250d0f3a9a1f13b7da
parent0e9194ca621751220d447b6a276f0c03ab19e020 (diff)
parenta806e77cb611342c1b5ccd266c9efa79ab2974b0 (diff)
Implement our own initialStateService for 15 (#1291)
Implement our own initialStateService for 15
-rw-r--r--lib/Controller/PageController.php15
-rw-r--r--templates/main.php5
-rw-r--r--tests/unit/Controller/PageControllerTest.php10
3 files changed, 17 insertions, 13 deletions
diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php
index 4f4c722e..eebfccf8 100644
--- a/lib/Controller/PageController.php
+++ b/lib/Controller/PageController.php
@@ -25,7 +25,7 @@ namespace OCA\Contacts\Controller;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
-use OCP\IInitialStateService;
+// use OCP\IInitialStateService;
use OCP\L10N\IFactory;
use OCP\IRequest;
@@ -33,20 +33,20 @@ class PageController extends Controller {
protected $appName;
- /** @var IInitialStateService */
- private $initialStateService;
+ // /** @var IInitialStateService */
+ // private $initialStateService;
/** @var IFactory */
private $languageFactory;
public function __construct(string $AppName,
IRequest $request,
- IInitialStateService $initialStateService,
+ // IInitialStateService $initialStateService,
IFactory $languageFactory) {
parent::__construct($AppName, $request);
$this->appName = $AppName;
- $this->initialStateService = $initialStateService;
+ // $this->initialStateService = $initialStateService;
$this->languageFactory = $languageFactory;
}
@@ -58,7 +58,8 @@ class PageController extends Controller {
*/
public function index(): TemplateResponse {
$locales = $this->languageFactory->findAvailableLocales();
- $this->initialStateService->provideInitialState($this->appName, 'locales', $locales);
- return new TemplateResponse('contacts', 'main'); // templates/main.php
+ // TODO: use initialStateService once min-version is 16!
+ // $this->initialStateService->provideInitialState($this->appName, 'locales', $locales);
+ return new TemplateResponse('contacts', 'main', ['locales' => json_encode($locales)]); // templates/main.php
}
}
diff --git a/templates/main.php b/templates/main.php
index 9fa58fc6..365cf629 100644
--- a/templates/main.php
+++ b/templates/main.php
@@ -2,8 +2,11 @@
if (!\OCP\Util::isIe()) {
script('contacts', 'contacts');
style('contacts', 'contacts');
-} else {
?>
+
+<input type="hidden" id="initial-state-contacts-locales" value="<?php p(base64_encode($_['locales'])); ?>">
+
+<?php } else { ?>
<div id="app-content">
<div class="emptycontent">
<div class="icon-contacts-dark"></div>
diff --git a/tests/unit/Controller/PageControllerTest.php b/tests/unit/Controller/PageControllerTest.php
index f23ef441..6090af17 100644
--- a/tests/unit/Controller/PageControllerTest.php
+++ b/tests/unit/Controller/PageControllerTest.php
@@ -25,7 +25,7 @@ namespace OCA\Contacts\Controller;
use OCP\AppFramework\Http\TemplateResponse;
use PHPUnit\Framework\MockObject\MockObject;
-use OCP\IInitialStateService;
+// use OCP\IInitialStateService;
use OCP\IRequest;
use OCP\L10N\IFactory;
use ChristophWurst\Nextcloud\Testing\TestCase;
@@ -38,8 +38,8 @@ class PageControllerTest extends TestCase {
/** @var IRequest|MockObject */
private $request;
- /** @var IInitialStateService|MockObject */
- private $initialStateService;
+ // /** @var IInitialStateService|MockObject */
+ // private $initialStateService;
/** @var IFactory|MockObject */
private $languageFactory;
@@ -48,13 +48,13 @@ class PageControllerTest extends TestCase {
parent::setUp();
$this->request = $this->createMock(IRequest::class);
- $this->initialStateService = $this->createMock(IInitialStateService::class);
+ // $this->initialStateService = $this->createMock(IInitialStateService::class);
$this->languageFactory = $this->createMock(IFactory::class);
$this->controller = new PageController(
'contacts',
$this->request,
- $this->initialStateService,
+ // $this->initialStateService,
$this->languageFactory
);
}