Home > Net >  How can I remove the delete button next to the choose file button in easyadmin symfony?
How can I remove the delete button next to the choose file button in easyadmin symfony?

Time:06-02

How can I remove the delete button next to the choose file button in easyadmin symfony?

i want to remove the delete button next to the choose file button

Image Of the delete button

class ProjectCrudController extends AbstractCrudController
{
    public static function getEntityFqcn(): string
    {
        return Project::class;
    }

    
    public function configureFields(string $pageName): iterable
    {

        $imageFile1= TextField::new('imageFile')->setFormType(VichImageType::class);
        $image1=ImageField::new('file')->setBasePath('/uploads/projects/');
        $imageFile2= TextField::new('imageFile2')->setFormType(VichImageType::class);
        $image2=ImageField::new('file2')->setBasePath('/uploads/projects/');
        $fields=[
            TextField::new('nom'),
            AssociationField::new('categorie'),
            TextareaField::new('description'),
            DateField::new('dateRealisation'),
            SlugField::new('slug')->setTargetFieldName('nom')->hideOnIndex(),
        ];
        if($pageName==Crud::PAGE_INDEX || $pageName == Crud::PAGE_DETAIL){
             $fields[]=$image1;
             $fields[]=$image2;
        }else{
             $fields[]=$imageFile1;
             $fields[]=$imageFile2;
        }
        return $fields;
    }


CodePudding user response:

ImageField is using FileUploadType as a form type.

If you look into it you can mind some options that can interest you:

//EasyCorp\Bundle\EasyAdminBundle\Form\Type\FileUploadType
        $view->vars['multiple'] = $options['multiple'];
        $view->vars['allow_add'] = $options['allow_add'];
        $view->vars['allow_delete'] = $options['allow_delete'];
        $view->vars['download_path'] = $options['download_path'];

For your VichFileType, it's the same option name that will help you.

You want to disabled the delete button, so you can use the option called allow_delete.

With easy admin, you can use setFormTypeOption($optionName, $optionValue) to modify form options.

So just do:

    $imageFile1= TextField::new('imageFile')
        ->setFormType(VichImageType::class)
        ->setFormTypeOption('allow_delete', false);
    $image1=ImageField::new('file')
        ->setBasePath('/uploads/projects/')
        ->setFormTypeOption('allow_delete', false);
    $imageFile2= TextField::new('imageFile2')
        ->setFormType(VichImageType::class)
        ->setFormTypeOption('allow_delete', false);
    $image2=ImageField::new('file2')
        ->setBasePath('/uploads/projects/')
        ->setFormTypeOption('allow_delete', false);
  • Related