CRUDlex\ControllerProvider::deleteFile PHP Method

deleteFile() public method

The controller for the "delete file" action.
public deleteFile ( Silex\Application $app, string $entity, string $id, string $field ) : Response
$app Silex\Application the Silex application
$entity string the current entity
$id string the instance id
$field string the field of the file to delete of the instance
return Symfony\Component\HttpFoundation\Response redirects to the instance details page or 404 on invalid input
    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]));
    }