I have a commercial entity for portfolio management I use vichImage, but I don't understand why I cannot modify or delete an image. I can't change the photo without modifying another form field.
<?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');
}
}
before it was enough to add this line, but now the file has changed now is this:
namespace EasyCorp\Bundle\EasyAdminBundle\Event;
/**
* @author Javier Eguiluz <[email protected]>
*/
final class BeforeEntityDeletedEvent extends AbstractLifecycleEvent
{
use StoppableEventTrait;
}
what can i do please?, I am a beginner, thank you in advance for your help.
it was just a spelling problem, I typed updated instead of update. and to delete just add ? before the string in the setCommercial photo property