public function handleSelect($id)
 {
     /** @var GamePicture $picture */
     $picture = $this->pictures->find($id);
     if (!$picture) {
         $this->flashMessage("Obrázek {$id} nebyl nalezen");
         $this->redirect('default');
     }
     $game = $picture->game;
     $game->primary_picture = $picture;
     $this->games->save($game);
     $this->flashMessage("Primární obrázek hry {$game->name} byl nasaven.");
     $this->redirect('default');
 }
 public function processForm(Form $form, $values)
 {
     $game = $this->games->find($values['id_game']);
     if (!$game) {
         $form['id_game']->addError("Hra nebyla nalezena");
         return;
     }
     $pictures = [];
     /** @var FileUpload $upload */
     foreach ($values['pictures'] as $upload) {
         $path = $this->imageManager->put($upload);
         if (!$path) {
             $form->addError("Obrázek {$upload->name} se nepodařilo nahrát");
             continue;
         }
         $picture = new Picture();
         $picture->path = $path;
         $picture->game = $game;
         $pictures[] = $picture;
     }
     $this->onSave($form, $pictures, $game);
 }
 public function createComponentEditGameForm()
 {
     $form = $this->editGameFormFactory->create();
     $form->onSave[] = function (Form $form, Game $game, GamePicture $picture = null, $tags = []) {
         if ($picture) {
             $game->primary_picture = $picture;
             $game->pictures->add($picture);
             $this->pictures->save($picture, false);
         }
         $game->completion_tags->clear();
         /** @var Tag $tag */
         foreach ($tags as $tag) {
             $game->completion_tags->add($tag);
         }
         $this->games->save($game);
         $this->flashMessage("Hra {$game->name} byla úspěšně přidána.");
         $this->redirect('default');
     };
     return $form;
 }