diff options
author | Elizabeth Danzberger <lizzy7128@tutanota.de> | 2024-07-24 15:59:37 -0400 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2024-07-25 11:11:40 +0200 |
commit | efe03ee690e2ba8080df63719eff119216c32ddb (patch) | |
tree | 2e8a2a879dbd99d54b7cfde680e8468703dc795e | |
parent | a7addcb88f22e2ed46b3d2379424f3f41535cd9d (diff) | |
download | nextcloud-server-efe03ee690e2ba8080df63719eff119216c32ddb.tar.gz nextcloud-server-efe03ee690e2ba8080df63719eff119216c32ddb.zip |
feat: Add support for filling fields to backend components
Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
-rw-r--r-- | apps/files/lib/Controller/TemplateController.php | 14 | ||||
-rw-r--r-- | lib/private/Files/Template/TemplateManager.php | 5 | ||||
-rw-r--r-- | lib/public/Files/Template/FileCreatedFromTemplateEvent.php | 12 |
3 files changed, 26 insertions, 5 deletions
diff --git a/apps/files/lib/Controller/TemplateController.php b/apps/files/lib/Controller/TemplateController.php index c5f0a2fb5e2..f4770cb5623 100644 --- a/apps/files/lib/Controller/TemplateController.php +++ b/apps/files/lib/Controller/TemplateController.php @@ -51,15 +51,25 @@ class TemplateController extends OCSController { * @param string $filePath Path of the file * @param string $templatePath Name of the template * @param string $templateType Type of the template + * @param array $templateFields Fields of the template * * @return DataResponse<Http::STATUS_OK, FilesTemplateFile, array{}> * @throws OCSForbiddenException Creating template is not allowed * * 200: Template created successfully */ - public function create(string $filePath, string $templatePath = '', string $templateType = 'user'): DataResponse { + public function create( + string $filePath, + string $templatePath = '', + string $templateType = 'user', + array $templateFields = [] + ): DataResponse { try { - return new DataResponse($this->templateManager->createFromTemplate($filePath, $templatePath, $templateType)); + return new DataResponse($this->templateManager->createFromTemplate( + $filePath, + $templatePath, + $templateType, + $templateFields)); } catch (GenericFileException $e) { throw new OCSForbiddenException($e->getMessage()); } diff --git a/lib/private/Files/Template/TemplateManager.php b/lib/private/Files/Template/TemplateManager.php index e9014c7c17e..8b20e86930a 100644 --- a/lib/private/Files/Template/TemplateManager.php +++ b/lib/private/Files/Template/TemplateManager.php @@ -128,10 +128,11 @@ class TemplateManager implements ITemplateManager { /** * @param string $filePath * @param string $templateId + * @param array $templateFields * @return array * @throws GenericFileException */ - public function createFromTemplate(string $filePath, string $templateId = '', string $templateType = 'user'): array { + public function createFromTemplate(string $filePath, string $templateId = '', string $templateType = 'user', array $templateFields = []): array { $userFolder = $this->rootFolder->getUserFolder($this->userId); try { $userFolder->get($filePath); @@ -158,7 +159,7 @@ class TemplateManager implements ITemplateManager { $template->copy($targetFile->getPath()); } } - $this->eventDispatcher->dispatchTyped(new FileCreatedFromTemplateEvent($template, $targetFile)); + $this->eventDispatcher->dispatchTyped(new FileCreatedFromTemplateEvent($template, $targetFile, $templateFields)); return $this->formatFile($userFolder->get($filePath)); } catch (\Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); diff --git a/lib/public/Files/Template/FileCreatedFromTemplateEvent.php b/lib/public/Files/Template/FileCreatedFromTemplateEvent.php index ed585504f70..0636d1dc251 100644 --- a/lib/public/Files/Template/FileCreatedFromTemplateEvent.php +++ b/lib/public/Files/Template/FileCreatedFromTemplateEvent.php @@ -17,15 +17,17 @@ use OCP\Files\File; class FileCreatedFromTemplateEvent extends Event { private $template; private $target; + private $templateFields; /** * @param File|null $template * @param File $target * @since 21.0.0 */ - public function __construct(?File $template, File $target) { + public function __construct(?File $template, File $target, array $templateFields) { $this->template = $template; $this->target = $target; + $this->templateFields = $templateFields; } /** @@ -37,6 +39,14 @@ class FileCreatedFromTemplateEvent extends Event { } /** + * @return array + * @since 30.0.0 + */ + public function getTemplateFields(): array { + return $this->templateFields; + } + + /** * @return File * @since 21.0.0 */ |