我有一个用于投资组合管理的商业实体,我使用 vichImage,但我不明白为什么我不能修改或删除图像。如果不修改另一个表单域,我无法更改照片。
<?php
namespace App\Controller\Admin;
use App\Entity\Commercial;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\ImageField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Vich\UploaderBundle\Form\Type\VichImageType;
class CommercialCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Commercial::class;
}
public function configureCrud(Crud $crud): Crud
{
return $crud
->setPageTitle(Crud::PAGE_INDEX, 'Commercial Gallery')
->setPageTitle(Crud::PAGE_NEW, 'Add Photos')
->setPageTitle(Crud::PAGE_EDIT, 'Edit Photo')
->setDefaultSort(['created_at' => 'DESC']);
}
public function configureFields(string $pageName): iterable
{
// Photos configuration
$imageFile = TextareaField::new('imageFile', 'Photo')->setFormType(VichImageType::class);
$image = ImageField::new('commercialPhoto', 'Photo')->setBasePath('images/commercial');
$fields = [
IdField::new('id')->onlyOnDetail(),
TextField::new('name', 'Services name'),
AssociationField::new('users', 'Published by')->hideOnForm(),
DateTimeField::new('created_at', 'Date')->hideOnForm(),
];
// CRUD ACTIONS
if ($pageName == Crud::PAGE_INDEX || $pageName == Crud::PAGE_DETAIL) {
$fields[] = $image; // afficher l'image dans la page Index et Detail
} else {
$fields[] = $imageFile; // afficher l'image dans la page Edit
}
return $fields;
}
public function configureActions(Actions $actions): Actions
{
return $actions // Add boutton show
->add(Crud::PAGE_INDEX, Action::DETAIL);
}
//create a filter
public function configureFilters(Filters $filters): Filters
{
return $filters
->add('name')
->add('users')
->add('created_at');
}
}
namespace EasyCorp\Bundle\EasyAdminBundle\Event;
/**
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
*/
final class BeforeEntityDeletedEvent extends AbstractLifecycleEvent
{
use StoppableEventTrait;
}
请问我该怎么办?,我是初学者,提前感谢您的帮助。