Passed
Pull Request — master (#132)
by
unknown
15:02 queued 06:44
created

DocumentFormController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A redirectToList() 0 3 1
B createAction() 0 37 7
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
19
class DocumentFormController extends AbstractDocumentFormController
20
{
21
22
    protected function redirectToList($message = null)
23
    {
24
        $this->redirect('list', 'DocumentForm', null, array('message' => $message));
25
    }
26
27
    /**
28
     * action create
29
     *
30
     * @param \EWW\Dpf\Domain\Model\DocumentForm $newDocumentForm
31
     * @return void
32
     */
33
    public function createAction(\EWW\Dpf\Domain\Model\DocumentForm $newDocumentForm)
34
    {
35
        foreach ($newDocumentForm->getNewFiles() as $newFile) {
36
            $uid = $newFile->getUID();
37
            if (empty($uid)) {
38
                $newFile->setDownload(true);
39
            }
40
            $files[] = $newFile;
41
        }
42
43
        $newDocumentForm->setNewFiles($files);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $files seems to be defined by a foreach iteration on line 35. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
44
45
        try {
46
            parent::createAction($newDocumentForm);
47
48
            if (key_exists('afterDocSavedRedirectPage',$this->settings) && $this->settings['afterDocSavedRedirectPage']) {
49
                $uri = $this->uriBuilder
50
                    ->setTargetPageUid($this->settings['afterDocSavedRedirectPage'])
51
                    ->build();
52
                $this->redirectToUri($uri);
53
            } else {
54
                $this->redirectToList('CREATE_OK');
55
            }
56
        } catch (\Exception $exception) {
57
58
            $severity = \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR;
59
60
            if ($exception instanceof DPFExceptionInterface) {
61
                $key = $exception->messageLanguageKey();
62
            } else {
63
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:error.unexpected';
64
            }
65
66
            $message[] = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($key, 'dpf');
0 ignored issues
show
Comprehensibility Best Practice introduced by
$message was never initialized. Although not strictly required by PHP, it is generally a good practice to add $message = array(); before regardless.
Loading history...
67
68
            $this->addFlashMessage(implode(" ", $message), '', $severity,true);
69
            $this->forward('new', 'DocumentForm', null, array('newDocumentForm' => $newDocumentForm));
70
        }
71
    }
72
}
73