Skip to content

Latest commit

 

History

History
44 lines (31 loc) · 1.91 KB

4-deleting-media.md

File metadata and controls

44 lines (31 loc) · 1.91 KB

Deleting media

###Automatically display a checkbox for deletion

In your entity form type, you can use two options provided by the bundle to automatically display a non mapped checkbox under your media :

->add('document', 'vlabs_file', array(
            'required' => false,
            'add_del' => true,
            'del_label' => 'Delete ?'
        ))

###Real deletion

This part needs to be improved, actually the removal is not done automatically. You must always handle it in your controller.

For example, if your form is called image, you must call the following code to permanently delete the media :

if ($form->isValid()) {
    if($form->has('delImage') && $form->get('delImage')->getData() == true) {
        $entity->setImage(null);
    }
    
    $em->persist($entity);
    $em->flush();
    
    return $this->redirect($this->generateUrl('foo'));
}

The del file name will always be delFieldName

Note that if it's an image, it will also be removed from cache.

Documentation