gaya/upload-widget
最新稳定版本:1.0.0
Composer 安装命令:
composer require gaya/upload-widget
包简介
Provide a widget to upload file with a progress bar.
README 文档
README
This extension provides a frontend widget to upload files in extbase forms.
This includes:
- a view helper for your template
- a controller to store the uploaded file in FAL
- a property validator for your model (DTO)
- a service to create a reference between the uploaded file and your final model
Installation
Intall upload_widget with Composer:
composer require gaya/upload_widget
Configuration
In your root template, include the TypoScript "Upload Widget"
Usage
You can test this extension by installing gaya/upload_widget_example. All explanations below come from this.
Form model
Create a DTO for your form and add the validator for the file property:
/**
* @var string
* @Extbase\Validate("NotEmpty")
* @Extbase\Validate("\GAYA\UploadWidget\Validation\Validator\ProtectedFileUidValidator")
*/
protected string $file = '';
Template
Call the view helper in your form template:
<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>
Controller
When your DTO is validated, you simply have to create a reference between the uploaded file and your stored object:
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);
}
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2023-02-08