gupalo/symfony-form-transformers
最新稳定版本:1.3.0
Composer 安装命令:
composer require gupalo/symfony-form-transformers
包简介
Symfony Form Transformers
README 文档
README
Symfony Forms TsvTransformer
How to Install
Install the gupalo/symfony-form-transformers package using composer:
composer require gupalo/symfony-form-transformers
Transformers
EmptyStringTransformer: allows user to pass empty fields which should be empty strings instead of nullJsonYamlTransformer: user views and edits field as YAML but it is stored as JSON in DB and is array in PHPStringArrayTransformer: user can enter several strings each from new line and they will become an arrayTsvTransformer: user copy-pastes from spreadsheet and PHP gets array with named keys (multiline and quoting are not supported)
Basic Usage
Add transformers to your forms
class YourEntity { private ?array $data = []; } /// class YourEntityType extends AbstractType { public function __construct(private JsonYamlTransformer $jsonYamlTransformer) { $this->jsonYamlTransformer = $jsonYamlTransformer; } public function buildForm(FormBuilderInterface $builder, array $options): void { $builder // ... ->add('data', TextareaType::class); $builder->get('data')->addModelTransformer($this->jsonYamlTransformer); }
Advanced Usage
Some transformers have options on construct. Options are public properties, you can change them later.
See tests for more examples. Also look at src - the logic is quite simple.
If you have multiline input Tsv, set TsvHelper::$multiline = true;
统计信息
- 总下载量: 11.63k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-11-25