diff options
author | Julius Härtl <jus@bitgrid.net> | 2019-12-16 14:58:56 +0100 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2019-12-16 17:22:53 +0100 |
commit | de5384466c4236181d21810142e3f2773bdeefe7 (patch) | |
tree | b3517808930b23fe43869830663201c5bf3267b1 /lib/private/DirectEditing/Manager.php | |
parent | 29f6f15cf3c63df07b81d7c97fe547f27a3906b3 (diff) | |
download | nextcloud-server-de5384466c4236181d21810142e3f2773bdeefe7.tar.gz nextcloud-server-de5384466c4236181d21810142e3f2773bdeefe7.zip |
Return empty template for default creators
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib/private/DirectEditing/Manager.php')
-rw-r--r-- | lib/private/DirectEditing/Manager.php | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/lib/private/DirectEditing/Manager.php b/lib/private/DirectEditing/Manager.php index fcaaf9e0303..a739402d629 100644 --- a/lib/private/DirectEditing/Manager.php +++ b/lib/private/DirectEditing/Manager.php @@ -40,7 +40,9 @@ use OCP\Files\IRootFolder; use OCP\Files\Node; use OCP\Files\NotFoundException; use OCP\IDBConnection; +use OCP\IL10N; use OCP\IUserSession; +use OCP\L10N\IFactory; use OCP\Security\ISecureRandom; use OCP\Share\IShare; @@ -61,17 +63,21 @@ class Manager implements IManager { private $random; private $userId; private $rootFolder; + /** @var IL10N */ + private $l10n; public function __construct( ISecureRandom $random, IDBConnection $connection, IUserSession $userSession, - IRootFolder $rootFolder + IRootFolder $rootFolder, + IFactory $l10nFactory ) { $this->random = $random; $this->connection = $connection; $this->userId = $userSession->getUser() ? $userSession->getUser()->getUID() : null; $this->rootFolder = $rootFolder; + $this->l10n = $l10nFactory->get('core'); } public function registerDirectEditor(IEditor $directEditor): void { @@ -88,8 +94,24 @@ class Manager implements IManager { } $templates = []; foreach ($this->editors[$editor]->getCreators() as $creator) { - if ($creator instanceof ACreateFromTemplate && $creator->getId() === $type) { - $templates = $creator->getTemplates(); + if ($creator->getId() === $type) { + $templates = [ + 'empty' => [ + 'id' => 'empty', + 'title' => $this->l10n->t('Empty file'), + 'preview' => null + ] + ]; + + if ($creator instanceof ACreateFromTemplate) { + $templates = $creator->getTemplates(); + } + + $templates = array_map(function ($template) use ($creator) { + $template['extension'] = $creator->getExtension(); + $template['mimetype'] = $creator->getMimetype(); + return $template; + }, $templates); } } $return = []; |