/**
  * Triggered on upload form preSave
  * Uploads the file
  *
  * @param ModelInterface $image   The image model to be saved.
  * @param Request        $request The request object.
  *
  * @return void
  */
 protected function onPreSave($image, Request $request = null)
 {
     if ($image instanceof ImageInterface) {
         $image->upload();
     }
 }
 /**
  * Process the POST/PUT submitted data,
  * Creates a form for the entity associated
  * to the controller, that is validated.
  * @param Request        $request         The request object.
  * @param ModelInterface $model           The form entity.
  * @param array          $formTypeOptions The form type options.
  * @param boolean        $triggerHooks    Trigger or not model hooks.
  * @param string         $formType        Optional form type name
  *
  * @return View
  */
 protected function processForm(Request $request, ModelInterface $model, $formTypeOptions = array(), $triggerHooks = true, $formType = null)
 {
     $view = null;
     $statusCode = $model->getId() ? Response::HTTP_OK : Response::HTTP_CREATED;
     // Create the FormType
     $form = $this->createFormFromType($formType, $model, $formTypeOptions);
     // Submit the form data
     $form->handleRequest($request);
     // If the submitted data is valid
     if ($form->isValid()) {
         // Form data is saved
         $model = $this->saveModel($model, $statusCode, $triggerHooks);
         // The result is displayed
         return $this->restView($model, $statusCode);
     } else {
         // Form errors are displayed
         $view = View::create($form->getErrors(), Response::HTTP_BAD_REQUEST);
     }
     return $view;
 }