gaya / upload-widget
提供带有进度条的文件上传小部件。
1.0.0
2023-02-08 00:37 UTC
Requires
- php: ^8.0
- ext-json: *
- typo3/cms-core: ^11.5
- typo3/cms-extbase: ^11.5
- typo3/cms-fluid: ^11.5
Suggests
- gaya/upload-widget-example: Example of using gaya/upload-widget extension.
This package is auto-updated.
Last update: 2024-09-10 17:04:18 UTC
README
本扩展提供用于在extbase表单中上传文件的前端小部件。
包括以下内容
- 模板视图助手
- 控制器以将上传的文件存储在FAL中
- 模型(DTO)的属性验证器
- 服务以在上传的文件和最终模型之间创建引用
安装
使用Composer安装upload_widget
composer require gaya/upload_widget
配置
在您的根模板中包含TypoScript "Upload Widget"。
使用方法
您可以通过安装gaya/upload_widget_example来测试此扩展。以下所有说明均来自此。
表单模型
为您的表单创建一个DTO并添加文件属性的验证器。
/**
* @var string
* @Extbase\Validate("NotEmpty")
* @Extbase\Validate("\GAYA\UploadWidget\Validation\Validator\ProtectedFileUidValidator")
*/
protected string $file = '';
模板
在表单模板中调用视图助手。
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"
xmlns:f="http://typo3.org/ns/TYPO3/Fluid/ViewHelpers"
xmlns:uw="http://typo3.org/ns/GAYA/UploadWidget/ViewHelpers"
data-namespace-typo3-fluid="true">
<f:form action="create" objectName="exampleForm" object="{exampleForm}" class="form">
<div class="form-group">
<label for="file">File</label>
<uw:form.upload property="file" id="file" class="form-control" />
</div>
</f:form>
</html>
控制器
当您的DTO被验证后,您只需在上传的文件和存储的对象之间创建引用即可。
public function createAction(ExampleForm $exampleForm)
{
$example = GeneralUtility::makeInstance(Example::class);
$example->setFile(
$this->uploadService->createExtbaseFileReferenceFromFile(
$this->uploadService->getFile($exampleForm->getFile()),
'tx_uploadwidgetexample_domain_model_example'
)
);
$this->exampleRepository->add($example);
}