From a115210f4e41d34274f530fc839de62586126ef1 Mon Sep 17 00:00:00 2001 From: "Bernd.Rederlechner@t-systems.com" Date: Tue, 5 Sep 2023 20:20:57 +0200 Subject: [PATCH 1/2] Backport stable26,27 JSResourceLocator to injected own theming version for l10n --- lib/private/TemplateLayout.php | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index 3ceef29c34d78..a3e88e1198c7e 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -46,6 +46,8 @@ use OC\Search\SearchQuery; use OC\Template\JSCombiner; use OC\Template\JSConfigHelper; +use OC\Template\JSResourceLocator; +use OC\AppFramework\Utility\QueryNotFoundException; use OCP\AppFramework\Http\TemplateResponse; use OCP\Defaults; use OCP\IConfig; @@ -68,6 +70,9 @@ class TemplateLayout extends \OC_Template { /** @var INavigationManager */ private $navigationManager; + /** @var JSResourceLocator|null */ + public static $jsLocator = null; + /** * @param string $renderAs * @param string $appId application id @@ -374,16 +379,24 @@ public function getAppNamefromPath($path) { public static function findJavascriptFiles($scripts) { // Read the selected theme from the config file $theme = \OC_Util::getTheme(); - - $locator = new \OC\Template\JSResourceLocator( - \OC::$server->get(LoggerInterface::class), - $theme, - [ \OC::$SERVERROOT => \OC::$WEBROOT ], - [ \OC::$SERVERROOT => \OC::$WEBROOT ], - \OC::$server->query(JSCombiner::class) - ); - $locator->find($scripts); - return $locator->getResources(); + try { + // we need the injected form coming with stable26 + if (self::$jsLocator === null) { + self::$jsLocator = \OCP\Server::get(JSResourceLocator::class); + } + } catch (QueryNotFoundException $eInject) { + // but keep the old version just in case theming is not available + self::$jsLocator = new JSResourceLocator( + \OC::$server->get(LoggerInterface::class), + $theme, + [ \OC::$SERVERROOT => \OC::$WEBROOT ], + [ \OC::$SERVERROOT => \OC::$WEBROOT ], + \OC::$server->query(JSCombiner::class) + ); + } + + self::$jsLocator->find($scripts); + return self::$jsLocator->getResources(); } /** From 3b3c05d1a121008f6b557f1a8a3c4f908ed71b56 Mon Sep 17 00:00:00 2001 From: "Bernd.Rederlechner@t-systems.com" Date: Tue, 5 Sep 2023 20:22:16 +0200 Subject: [PATCH 2/2] Clean up code --- lib/private/TemplateLayout.php | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index a3e88e1198c7e..811f452ee9cac 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -43,11 +43,11 @@ namespace OC; use bantu\IniGetWrapper\IniGetWrapper; +use OC\AppFramework\Utility\QueryNotFoundException; use OC\Search\SearchQuery; use OC\Template\JSCombiner; use OC\Template\JSConfigHelper; use OC\Template\JSResourceLocator; -use OC\AppFramework\Utility\QueryNotFoundException; use OCP\AppFramework\Http\TemplateResponse; use OCP\Defaults; use OCP\IConfig; @@ -70,7 +70,7 @@ class TemplateLayout extends \OC_Template { /** @var INavigationManager */ private $navigationManager; - /** @var JSResourceLocator|null */ + /** @var JSResourceLocator|null */ public static $jsLocator = null; /** @@ -379,21 +379,21 @@ public function getAppNamefromPath($path) { public static function findJavascriptFiles($scripts) { // Read the selected theme from the config file $theme = \OC_Util::getTheme(); - try { - // we need the injected form coming with stable26 - if (self::$jsLocator === null) { - self::$jsLocator = \OCP\Server::get(JSResourceLocator::class); - } - } catch (QueryNotFoundException $eInject) { - // but keep the old version just in case theming is not available - self::$jsLocator = new JSResourceLocator( - \OC::$server->get(LoggerInterface::class), - $theme, - [ \OC::$SERVERROOT => \OC::$WEBROOT ], - [ \OC::$SERVERROOT => \OC::$WEBROOT ], - \OC::$server->query(JSCombiner::class) - ); - } + try { + // we need the injected form coming with stable26 + if (self::$jsLocator === null) { + self::$jsLocator = \OCP\Server::get(JSResourceLocator::class); + } + } catch (QueryNotFoundException $eInject) { + // but keep the old version just in case theming is not available + self::$jsLocator = new JSResourceLocator( + \OC::$server->get(LoggerInterface::class), + $theme, + [ \OC::$SERVERROOT => \OC::$WEBROOT ], + [ \OC::$SERVERROOT => \OC::$WEBROOT ], + \OC::$server->query(JSCombiner::class) + ); + } self::$jsLocator->find($scripts); return self::$jsLocator->getResources();