【发布时间】:2019-08-23 21:54:51
【问题描述】:
我有一个注册为 Sylius 资源的自定义实体。这个实体可以有一个图像列表。对于我的用例,我按照Docs 上的说明进行操作。
我使用 ImageType 的子类来提供 Upload-Image-Form:
艺术家图像类型:
<?php
declare(strict_types=1);
namespace AppBundle\Form\Type;
use Sylius\Bundle\CoreBundle\Form\Type\ImageType;
class ArtistImageType extends ImageType
{
/**
* {@inheritdoc}
*/
public function getBlockPrefix(): string
{
return 'artist_image';
}
}
这就是我在 FormType 中重用此 ArtistImageType 的方式:
final class ArtistType extends AbstractResourceType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', TextType::class, [
'empty_data' => '',
])
->add('firstName', TextType::class, [
'empty_data' => '',
'required' => false,
])
->add('lastName', TextType::class, [
'empty_data' => '',
])
->add('images', CollectionType::class, [
'entry_type' => ArtistImageType::class,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'label' => 'app.images',
])
还有form.html.twig:
<div class="ui two column stackable grid">
{{ form_errors(form) }}
<div class="column">
<div class="ui segment">
<h4 class="ui dividing header">{{ 'sylius.ui.general_info'|trans }}</h4>
<div class="two fields">
{{ form_row(form.name) }}
</div>
{{ form_row(form.images) }}
</div>
<div class="ui segment">
{{ form_row(form.firstName) }}
{{ form_row(form.lastName) }}
</div>
</div>
我想知道如何显示已经上传到类似于 Product-Form 的现有实体中的图像,其中现有图像显示在“选择文件”按钮旁边?
这就是我想要实现的目标:
但它仍然在没有任何预览的情况下被渲染。显然需要进一步定制。
【问题讨论】: