From 1aa103ef6945487b8c7118102b508760dd2d314d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 26 Mar 2021 15:44:57 +0100 Subject: [PATCH] remove usages of deprecated OCA\Files\App::getNavigationManager Signed-off-by: Robin Appelman --- apps/files/lib/AppInfo/Application.php | 9 ++++--- apps/files/lib/Controller/ApiController.php | 25 ++++++++++++------- apps/files/lib/Controller/ViewController.php | 9 +++++-- apps/files_external/appinfo/app.php | 4 ++- .../files_sharing/lib/AppInfo/Application.php | 6 +++-- .../lib/AppInfo/Application.php | 23 +++++++++-------- apps/systemtags/lib/AppInfo/Application.php | 21 +++++++++------- 7 files changed, 60 insertions(+), 37 deletions(-) diff --git a/apps/files/lib/AppInfo/Application.php b/apps/files/lib/AppInfo/Application.php index 92f29bfe410ad..e2f79a0a42c39 100644 --- a/apps/files/lib/AppInfo/Application.php +++ b/apps/files/lib/AppInfo/Application.php @@ -47,6 +47,7 @@ use OCA\Files\Notification\Notifier; use OCA\Files\Search\FilesSearchProvider; use OCA\Files\Service\TagService; +use OCA\Files\SidebarNavigationManager; use OCP\Activity\IManager as IActivityManager; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; @@ -149,8 +150,8 @@ private function registerTemplates(): void { $templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods'); } - private function registerNavigation(IL10N $l10n): void { - \OCA\Files\App::getNavigationManager()->add(function () use ($l10n) { + private function registerNavigation(IL10N $l10n, SidebarNavigationManager $navigation): void { + $navigation->add(function () use ($l10n) { return [ 'id' => 'files', 'appname' => 'files', @@ -159,7 +160,7 @@ private function registerNavigation(IL10N $l10n): void { 'name' => $l10n->t('All files') ]; }); - \OCA\Files\App::getNavigationManager()->add(function () use ($l10n) { + $navigation->add(function () use ($l10n) { return [ 'id' => 'recent', 'appname' => 'files', @@ -168,7 +169,7 @@ private function registerNavigation(IL10N $l10n): void { 'name' => $l10n->t('Recent') ]; }); - \OCA\Files\App::getNavigationManager()->add(function () use ($l10n) { + $navigation->add(function () use ($l10n) { return [ 'id' => 'favorites', 'appname' => 'files', diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php index 0cf261af72678..d2d5d40ec3f0e 100644 --- a/apps/files/lib/Controller/ApiController.php +++ b/apps/files/lib/Controller/ApiController.php @@ -39,6 +39,7 @@ use OC\Files\Node\Node; use OCA\Files\Service\TagService; +use OCA\Files\SidebarNavigationManager; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; @@ -73,6 +74,8 @@ class ApiController extends Controller { private $config; /** @var Folder */ private $userFolder; + /** @var SidebarNavigationManager */ + private $navigationManager; /** * @param string $appName @@ -84,14 +87,17 @@ class ApiController extends Controller { * @param IConfig $config * @param Folder $userFolder */ - public function __construct($appName, - IRequest $request, - IUserSession $userSession, - TagService $tagService, - IPreview $previewManager, - IManager $shareManager, - IConfig $config, - Folder $userFolder) { + public function __construct( + $appName, + IRequest $request, + IUserSession $userSession, + TagService $tagService, + IPreview $previewManager, + IManager $shareManager, + IConfig $config, + Folder $userFolder, + SidebarNavigationManager $navigationManager + ) { parent::__construct($appName, $request); $this->userSession = $userSession; $this->tagService = $tagService; @@ -99,6 +105,7 @@ public function __construct($appName, $this->shareManager = $shareManager; $this->config = $config; $this->userFolder = $userFolder; + $this->navigationManager = $navigationManager; } /** @@ -331,7 +338,7 @@ public function getGridView() { */ public function toggleShowFolder(int $show, string $key) { // ensure the edited key exists - $navItems = \OCA\Files\App::getNavigationManager()->getAll(); + $navItems = $this->navigationManager->getAll(); foreach ($navItems as $item) { // check if data is valid if (($show === 0 || $show === 1) && isset($item['expandedState']) && $key === $item['expandedState']) { diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index efaf2dc602f0e..8b0381592b5c1 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -37,6 +37,7 @@ use OCA\Files\Activity\Helper; use OCA\Files\Event\LoadAdditionalScriptsEvent; use OCA\Files\Event\LoadSidebar; +use OCA\Files\SidebarNavigationManager; use OCA\Viewer\Event\LoadViewer; use OCP\App\IAppManager; use OCP\AppFramework\Controller; @@ -86,6 +87,8 @@ class ViewController extends Controller { private $initialState; /** @var ITemplateManager */ private $templateManager; + /** @var SidebarNavigationManager */ + private $navigationManager; public function __construct(string $appName, IRequest $request, @@ -98,7 +101,8 @@ public function __construct(string $appName, IRootFolder $rootFolder, Helper $activityHelper, IInitialState $initialState, - ITemplateManager $templateManager + ITemplateManager $templateManager, + SidebarNavigationManager $navigationManager ) { parent::__construct($appName, $request); $this->appName = $appName; @@ -113,6 +117,7 @@ public function __construct(string $appName, $this->activityHelper = $activityHelper; $this->initialState = $initialState; $this->templateManager = $templateManager; + $this->navigationManager = $navigationManager; } /** @@ -233,7 +238,7 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal $navBarPositionPosition++; } - $navItems = \OCA\Files\App::getNavigationManager()->getAll(); + $navItems = $this->navigationManager->getAll(); // add the favorites entry in menu $navItems['favorites']['sublist'] = $favoritesSublistArray; diff --git a/apps/files_external/appinfo/app.php b/apps/files_external/appinfo/app.php index f8f7d377bc717..c1f7b275d034d 100644 --- a/apps/files_external/appinfo/app.php +++ b/apps/files_external/appinfo/app.php @@ -26,6 +26,7 @@ * */ +use OCA\Files\SidebarNavigationManager; use OCA\Files_External\Config\ConfigAdapter; require_once __DIR__ . '/../3rdparty/autoload.php'; @@ -36,7 +37,8 @@ $appContainer = \OCA\Files_External\MountConfig::$app->getContainer(); -\OCA\Files\App::getNavigationManager()->add(function () { +$navigationManager = $appContainer->get(SidebarNavigationManager::class); +$navigationManager->add(function () { $l = \OC::$server->getL10N('files_external'); return [ 'id' => 'extstoragemounts', diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php index 078a0a5f59dee..087cf545f8800 100644 --- a/apps/files_sharing/lib/AppInfo/Application.php +++ b/apps/files_sharing/lib/AppInfo/Application.php @@ -31,6 +31,7 @@ namespace OCA\Files_Sharing\AppInfo; use OC\AppFramework\Utility\SimpleContainer; +use OCA\Files\SidebarNavigationManager; use OCA\Files_Sharing\Capabilities; use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent; use OCA\Files_Sharing\External\Manager; @@ -172,9 +173,10 @@ protected function setupSharingMenus() { return; } + /** @var SidebarNavigationManager $navigationManager */ + $navigationManager = $this->getContainer()->get(SidebarNavigationManager::class); // show_Quick_Access stored as string - \OCA\Files\App::getNavigationManager()->add(function () { - $config = \OC::$server->getConfig(); + $navigationManager->add(function () use ($config) { $l = \OC::$server->getL10N('files_sharing'); $sharingSublistArray = []; diff --git a/apps/files_trashbin/lib/AppInfo/Application.php b/apps/files_trashbin/lib/AppInfo/Application.php index a14b49ba77b02..c680b6e0c6622 100644 --- a/apps/files_trashbin/lib/AppInfo/Application.php +++ b/apps/files_trashbin/lib/AppInfo/Application.php @@ -27,6 +27,7 @@ namespace OCA\Files_Trashbin\AppInfo; use OCA\DAV\Connector\Sabre\Principal; +use OCA\Files\SidebarNavigationManager; use OCA\Files_Trashbin\Capabilities; use OCA\Files_Trashbin\Expiration; use OCA\Files_Trashbin\Trash\ITrashManager; @@ -65,16 +66,18 @@ public function boot(IBootContext $context): void { // pre and post-rename, disable trash logic for the copy+unlink case \OCP\Util::connectHook('OC_Filesystem', 'delete', 'OCA\Files_Trashbin\Trashbin', 'ensureFileScannedHook'); - \OCA\Files\App::getNavigationManager()->add(function () { - $l = \OC::$server->getL10N('files_trashbin'); - return [ - 'id' => 'trashbin', - 'appname' => 'files_trashbin', - 'script' => 'list.php', - 'order' => 50, - 'name' => $l->t('Deleted files'), - 'classes' => 'pinned', - ]; + $context->injectFn(function (SidebarNavigationManager $navigationManager) { + $navigationManager->add(function () { + $l = \OC::$server->getL10N('files_trashbin'); + return [ + 'id' => 'trashbin', + 'appname' => 'files_trashbin', + 'script' => 'list.php', + 'order' => 50, + 'name' => $l->t('Deleted files'), + 'classes' => 'pinned', + ]; + }); }); } diff --git a/apps/systemtags/lib/AppInfo/Application.php b/apps/systemtags/lib/AppInfo/Application.php index 15f2a6e698958..5e72a10b5a35a 100644 --- a/apps/systemtags/lib/AppInfo/Application.php +++ b/apps/systemtags/lib/AppInfo/Application.php @@ -26,6 +26,7 @@ namespace OCA\SystemTags\AppInfo; +use OCA\Files\SidebarNavigationManager; use OCA\SystemTags\Activity\Listener; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; @@ -77,15 +78,17 @@ function () { $dispatcher->addListener(MapperEvent::EVENT_UNASSIGN, $mapperListener); }); - \OCA\Files\App::getNavigationManager()->add(function () { - $l = \OC::$server->getL10N(self::APP_ID); - return [ - 'id' => 'systemtagsfilter', - 'appname' => self::APP_ID, - 'script' => 'list.php', - 'order' => 25, - 'name' => $l->t('Tags'), - ]; + $context->injectFn(function (SidebarNavigationManager $navigationManager) { + $navigationManager->add(function () { + $l = \OC::$server->getL10N(self::APP_ID); + return [ + 'id' => 'systemtagsfilter', + 'appname' => self::APP_ID, + 'script' => 'list.php', + 'order' => 25, + 'name' => $l->t('Tags'), + ]; + }); }); } }