diff options
author | Julius Härtl <jus@bitgrid.net> | 2023-03-02 22:15:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-02 22:15:15 +0100 |
commit | c76be650142a93291c8e5f197958995e35793142 (patch) | |
tree | 0d4327f10a57dbee8929579ea4ceabe290f2697f /lib | |
parent | b6d8fc97afe28bc1b017026447264ba37ed37caa (diff) | |
parent | 38e4f8ae61d1176d87072167e0f081326d01edda (diff) | |
download | nextcloud-server-c76be650142a93291c8e5f197958995e35793142.tar.gz nextcloud-server-c76be650142a93291c8e5f197958995e35793142.zip |
Merge pull request #33755 from nextcloud/enh/reference-file
File widget for references
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Collaboration/Reference/File/FileReferenceProvider.php | 42 | ||||
-rw-r--r-- | lib/public/RichObjectStrings/Definitions.php | 6 |
2 files changed, 39 insertions, 9 deletions
diff --git a/lib/private/Collaboration/Reference/File/FileReferenceProvider.php b/lib/private/Collaboration/Reference/File/FileReferenceProvider.php index 95e49cdf860..d423a830495 100644 --- a/lib/private/Collaboration/Reference/File/FileReferenceProvider.php +++ b/lib/private/Collaboration/Reference/File/FileReferenceProvider.php @@ -25,8 +25,8 @@ declare(strict_types=1); namespace OC\Collaboration\Reference\File; use OC\User\NoUserException; +use OCP\Collaboration\Reference\ADiscoverableReferenceProvider; use OCP\Collaboration\Reference\IReference; -use OCP\Collaboration\Reference\IReferenceProvider; use OCP\Collaboration\Reference\Reference; use OCP\Files\IMimeTypeDetector; use OCP\Files\InvalidPathException; @@ -34,27 +34,34 @@ use OCP\Files\IRootFolder; use OCP\Files\Node; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; +use OCP\IL10N; use OCP\IPreview; use OCP\IURLGenerator; use OCP\IUserSession; +use OCP\L10N\IFactory; -class FileReferenceProvider implements IReferenceProvider { +class FileReferenceProvider extends ADiscoverableReferenceProvider { private IURLGenerator $urlGenerator; private IRootFolder $rootFolder; private ?string $userId; private IPreview $previewManager; private IMimeTypeDetector $mimeTypeDetector; - - public function __construct(IURLGenerator $urlGenerator, - IRootFolder $rootFolder, - IUserSession $userSession, - IMimeTypeDetector $mimeTypeDetector, - IPreview $previewManager) { + private IL10N $l10n; + + public function __construct( + IURLGenerator $urlGenerator, + IRootFolder $rootFolder, + IUserSession $userSession, + IMimeTypeDetector $mimeTypeDetector, + IPreview $previewManager, + IFactory $l10n + ) { $this->urlGenerator = $urlGenerator; $this->rootFolder = $rootFolder; $this->userId = $userSession->getUser() ? $userSession->getUser()->getUID() : null; $this->previewManager = $previewManager; $this->mimeTypeDetector = $mimeTypeDetector; + $this->l10n = $l10n->get('files'); } public function matchReference(string $referenceText): bool { @@ -145,9 +152,10 @@ class FileReferenceProvider implements IReferenceProvider { 'id' => $file->getId(), 'name' => $file->getName(), 'size' => $file->getSize(), - 'path' => $file->getPath(), + 'path' => $userFolder->getRelativePath($file->getPath()), 'link' => $reference->getUrl(), 'mimetype' => $file->getMimetype(), + 'mtime' => $file->getMTime(), 'preview-available' => $this->previewManager->isAvailable($file) ]); } catch (InvalidPathException|NotFoundException|NotPermittedException|NoUserException $e) { @@ -162,4 +170,20 @@ class FileReferenceProvider implements IReferenceProvider { public function getCacheKey(string $referenceId): ?string { return $this->userId ?? ''; } + + public function getId(): string { + return 'files'; + } + + public function getTitle(): string { + return $this->l10n->t('Files'); + } + + public function getOrder(): int { + return 0; + } + + public function getIconUrl(): string { + return $this->urlGenerator->imagePath('files', 'folder.svg'); + } } diff --git a/lib/public/RichObjectStrings/Definitions.php b/lib/public/RichObjectStrings/Definitions.php index 383d626c155..57da9f4eb30 100644 --- a/lib/public/RichObjectStrings/Definitions.php +++ b/lib/public/RichObjectStrings/Definitions.php @@ -347,6 +347,12 @@ class Definitions { 'description' => 'Whether or not a preview is available. If `no` the mimetype icon should be used', 'example' => 'yes', ], + 'mtime' => [ + 'since' => '25.0.0', + 'required' => false, + 'description' => 'The mtime of the file/folder as unix timestamp', + 'example' => '1661854213', + ], ], ], 'forms-form' => [ |