createFiles() public method

Creates the uploaded files of a newly created entity.
public createFiles ( Request $request, Entity $entity, string $entityName ) : boolean
$request Symfony\Component\HttpFoundation\Request the HTTP request containing the file data
$entity Entity the just created entity
$entityName string the name of the entity as this class here is not aware of it
return boolean true if all before events passed
Example #1
0
 /**
  * Postprocesses the entity after modification by handling the uploaded
  * files and setting the flash.
  *
  * @param Application $app
  * the current application
  * @param AbstractData $crudData
  * the data instance of the entity
  * @param Entity $instance
  * the entity
  * @param string $entity
  * the name of the entity
  * @param string $mode
  * whether to 'edit' or to 'create' the entity
  *
  * @return null|\Symfony\Component\HttpFoundation\RedirectResponse
  * the HTTP response of this modification
  */
 protected function modifyFilesAndSetFlashBag(Application $app, AbstractData $crudData, Entity $instance, $entity, $mode)
 {
     $id = $instance->get('id');
     $request = $app['request_stack']->getCurrentRequest();
     $result = $mode == 'edit' ? $crudData->updateFiles($request, $instance, $entity) : $crudData->createFiles($request, $instance, $entity);
     if (!$result) {
         return null;
     }
     $app['session']->getFlashBag()->add('success', $app['translator']->trans('crudlex.' . $mode . '.success', ['%label%' => $crudData->getDefinition()->getLabel(), '%id%' => $id]));
     return $app->redirect($app['url_generator']->generate('crudShow', ['entity' => $entity, 'id' => $id]));
 }