| 1 | <?php |
||
| 2 | namespace EWW\Dpf\Controller; |
||
| 3 | |||
| 4 | /* |
||
| 5 | * This file is part of the TYPO3 CMS project. |
||
| 6 | * |
||
| 7 | * It is free software; you can redistribute it and/or modify it under |
||
| 8 | * the terms of the GNU General Public License, either version 2 |
||
| 9 | * of the License, or any later version. |
||
| 10 | * |
||
| 11 | * For the full copyright and license information, please read the |
||
| 12 | * LICENSE.txt file that was distributed with this source code. |
||
| 13 | * |
||
| 14 | * The TYPO3 project - inspiring people to share! |
||
| 15 | */ |
||
| 16 | |||
| 17 | use EWW\Dpf\Exceptions\DPFExceptionInterface; |
||
| 18 | use EWW\Dpf\Helper\DocumentMapper; |
||
| 19 | use EWW\Dpf\Services\Email\Notifier; |
||
| 20 | |||
| 21 | class DocumentFormController extends AbstractDocumentFormController |
||
| 22 | { |
||
| 23 | |||
| 24 | protected function redirectToList($message = null) |
||
| 25 | { |
||
| 26 | $this->redirect('list', 'DocumentForm', null, array('message' => $message)); |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * action new |
||
| 31 | * |
||
| 32 | * @param \EWW\Dpf\Domain\Model\DocumentForm $newDocumentForm |
||
| 33 | * @param int $returnDocumentId |
||
| 34 | * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation("newDocumentForm") |
||
| 35 | * @return void |
||
| 36 | */ |
||
| 37 | public function newAction(\EWW\Dpf\Domain\Model\DocumentForm $newDocumentForm = null, $returnDocumentId = 0) |
||
| 38 | { |
||
| 39 | $this->view->assign('documentForm', $newDocumentForm); |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * action create |
||
| 44 | * |
||
| 45 | * @param \EWW\Dpf\Domain\Model\DocumentForm $newDocumentForm |
||
| 46 | * @return void |
||
| 47 | */ |
||
| 48 | public function createAction(\EWW\Dpf\Domain\Model\DocumentForm $newDocumentForm) |
||
| 49 | { |
||
| 50 | foreach ($newDocumentForm->getFiles() as $file) { |
||
| 51 | $uid = $file->getUID(); |
||
| 52 | if (empty($uid)) { |
||
| 53 | $file->setDownload(true); |
||
| 54 | } |
||
| 55 | $files[] = $file; |
||
| 56 | } |
||
| 57 | |||
| 58 | $newDocumentForm->setFiles($files); |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
| 59 | |||
| 60 | try { |
||
| 61 | parent::createAction($newDocumentForm); |
||
| 62 | |||
| 63 | /** @var \EWW\Dpf\Helper\DocumentMapper $documentMapper */ |
||
| 64 | $documentMapper = $this->objectManager->get(DocumentMapper::class); |
||
| 65 | |||
| 66 | /** @var \EWW\Dpf\Domain\Model\Document $newDocument */ |
||
| 67 | $newDocument = $documentMapper->getDocument($newDocumentForm); |
||
| 68 | |||
| 69 | /** @var Notifier $notifier */ |
||
| 70 | $notifier = $this->objectManager->get(Notifier::class); |
||
| 71 | $notifier->sendNewDocumentNotification($newDocument); |
||
| 72 | |||
| 73 | if (key_exists('afterDocSavedRedirectPage',$this->settings) && $this->settings['afterDocSavedRedirectPage']) { |
||
| 74 | $uri = $this->uriBuilder |
||
| 75 | ->setTargetPageUid($this->settings['afterDocSavedRedirectPage']) |
||
| 76 | ->build(); |
||
| 77 | $this->redirectToUri($uri); |
||
| 78 | } else { |
||
| 79 | $this->redirectToList('CREATE_OK'); |
||
| 80 | } |
||
| 81 | } catch (\Exception $exception) { |
||
| 82 | |||
| 83 | $severity = \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR; |
||
| 84 | |||
| 85 | if ($exception instanceof DPFExceptionInterface) { |
||
| 86 | $key = $exception->messageLanguageKey(); |
||
| 87 | } else { |
||
| 88 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:error.unexpected'; |
||
| 89 | } |
||
| 90 | |||
| 91 | $message[] = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($key, 'dpf'); |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 92 | |||
| 93 | $this->addFlashMessage(implode(" ", $message), '', $severity,true); |
||
| 94 | $this->forward('new', 'DocumentForm', null, array('newDocumentForm' => $newDocumentForm)); |
||
| 95 | } |
||
| 96 | } |
||
| 97 | } |
||
| 98 |