public function deleteFile(Application $app, $entity, $id, $field)
{
$crudData = $app['crud']->getData($entity);
$instance = $crudData->get($id);
if (!$instance) {
return $this->getNotFoundPage($app, $app['translator']->trans('crudlex.instanceNotFound'));
}
if (!$crudData->getDefinition()->getField($field, 'required', false) && $crudData->deleteFile($instance, $entity, $field)) {
$instance->set($field, '');
$crudData->update($instance);
$app['session']->getFlashBag()->add('success', $app['translator']->trans('crudlex.file.deleted'));
} else {
$app['session']->getFlashBag()->add('danger', $app['translator']->trans('crudlex.file.notDeleted'));
}
return $app->redirect($app['url_generator']->generate('crudShow', ['entity' => $entity, 'id' => $id]));
}