/** * @{inheritdoc} */ public function handle(FormInterface $form, $attributes = array()) { if (!$form->isValid()) { return false; } $mediaIds = []; if ($form->has('files')) { $files = $form['files']->getData(); if (count($files)) { $type = $this->formExtension->getType($form->getName()); $collectionId = $type->getCollectionId(); $ids = []; /** @var UploadedFile $file */ foreach ($form['files']->getData() as $file) { if ($file instanceof UploadedFile) { $media = $this->mediaManager->save($file, ['collection' => $collectionId, 'locale' => $form->get('locale')->getData(), 'title' => $file->getClientOriginalName()], null); $ids[] = $media->getId(); } } $mediaIds['files'] = $ids; } } $attributes['form'] = $form; $this->saveForm($form, $attributes, $mediaIds); $type = $this->formExtension->getType($form->getName()); if ($type instanceof TypeInterface) { $this->sendMails($type, $attributes, $form); } return true; }
/** * @dataProvider provideSpecialCharacterFileName */ public function testSpecialCharacterFileName($fileName, $cleanUpArgument) { /** @var UploadedFile $uploadedFile */ $uploadedFile = $this->prophesize(UploadedFile::class)->willBeConstructedWith(['', 1, null, null, 1, true]); $uploadedFile->getClientOriginalName()->willReturn($fileName); $uploadedFile->getPathname()->willReturn(''); $uploadedFile->getSize()->willReturn('123'); $uploadedFile->getMimeType()->willReturn('img'); $user = $this->prophesize(User::class)->willImplement(UserInterface::class); $this->userRepository->findUserById(1)->willReturn($user); $this->pathCleaner->cleanup(Argument::exact($cleanUpArgument))->shouldBeCalled(); $this->mediaManager->save($uploadedFile->reveal(), ['locale' => 'en', 'title' => 'my title'], 1); }