mirror of
https://github.com/nextcloud/server.git
synced 2025-08-16 15:41:57 +00:00
feat: Add support for filling fields to backend components
Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
This commit is contained in:

committed by
Julius Härtl

parent
a7addcb88f
commit
efe03ee690
@ -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());
|
||||
}
|
||||
|
@ -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]);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -36,6 +38,14 @@ class FileCreatedFromTemplateEvent extends Event {
|
||||
return $this->template;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @since 30.0.0
|
||||
*/
|
||||
public function getTemplateFields(): array {
|
||||
return $this->templateFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return File
|
||||
* @since 21.0.0
|
||||
|
Reference in New Issue
Block a user