Skip to content

Commit 7df7f27

Browse files
committed
Merge #254 [backport25] Dependency injection of JSResourceLocator
2 parents 9f3d7dd + 3b3c05d commit 7df7f27

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

lib/private/TemplateLayout.php

+22-9
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@
4343
namespace OC;
4444

4545
use bantu\IniGetWrapper\IniGetWrapper;
46+
use OC\AppFramework\Utility\QueryNotFoundException;
4647
use OC\Search\SearchQuery;
4748
use OC\Template\JSCombiner;
4849
use OC\Template\JSConfigHelper;
50+
use OC\Template\JSResourceLocator;
4951
use OCP\AppFramework\Http\TemplateResponse;
5052
use OCP\Defaults;
5153
use OCP\IConfig;
@@ -68,6 +70,9 @@ class TemplateLayout extends \OC_Template {
6870
/** @var INavigationManager */
6971
private $navigationManager;
7072

73+
/** @var JSResourceLocator|null */
74+
public static $jsLocator = null;
75+
7176
/**
7277
* @param string $renderAs
7378
* @param string $appId application id
@@ -374,16 +379,24 @@ public function getAppNamefromPath($path) {
374379
public static function findJavascriptFiles($scripts) {
375380
// Read the selected theme from the config file
376381
$theme = \OC_Util::getTheme();
377-
378-
$locator = new \OC\Template\JSResourceLocator(
379-
\OC::$server->get(LoggerInterface::class),
380-
$theme,
381-
[ \OC::$SERVERROOT => \OC::$WEBROOT ],
382-
[ \OC::$SERVERROOT => \OC::$WEBROOT ],
383-
\OC::$server->query(JSCombiner::class)
382+
try {
383+
// we need the injected form coming with stable26
384+
if (self::$jsLocator === null) {
385+
self::$jsLocator = \OCP\Server::get(JSResourceLocator::class);
386+
}
387+
} catch (QueryNotFoundException $eInject) {
388+
// but keep the old version just in case theming is not available
389+
self::$jsLocator = new JSResourceLocator(
390+
\OC::$server->get(LoggerInterface::class),
391+
$theme,
392+
[ \OC::$SERVERROOT => \OC::$WEBROOT ],
393+
[ \OC::$SERVERROOT => \OC::$WEBROOT ],
394+
\OC::$server->query(JSCombiner::class)
384395
);
385-
$locator->find($scripts);
386-
return $locator->getResources();
396+
}
397+
398+
self::$jsLocator->find($scripts);
399+
return self::$jsLocator->getResources();
387400
}
388401

389402
/**

0 commit comments

Comments
 (0)