Passed
Pull Request — master (#108)
by Ralf
04:08 queued 20s
created

PreviewViewHelper::initialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
namespace EWW\Dpf\ViewHelpers\Link;
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 TYPO3\CMS\Core\Utility\GeneralUtility;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Core\Utility\GeneralUtility was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use TYPO3\CMS\Core\Utility\MathUtility;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Core\Utility\MathUtility was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use TYPO3\CMS\Backend\Utility\BackendUtility;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Backend\Utility\BackendUtility was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Fluid\ViewHelp...stractBackendViewHelper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Config...urationManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
23
class PreviewViewHelper extends AbstractBackendViewHelper
24
{
25
26
    /**
27
     * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
28
     * @inject
29
     */
30
    protected $configurationManager;
31
32
    /**
33
     * documentRepository
34
     *
35
     * @var \EWW\Dpf\Domain\Repository\DocumentRepository
36
     * @inject
37
     */
38
    protected $documentRepository;
39
40
    /**
41
     * Secret API key for delivering inactive documents.
42
     * @var string
43
     */
44
    private $secretKey;
45
46
    /**
47
     * Initialize secret key from plugin TYPOScript configuration.
48
     */
49
    public function initialize() {
50
        parent::initialize();
51
52
        $settings = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
53
54
        if (isset($settings['plugin.']['tx_dpf.']['settings.']['deliverInactiveSecretKey'])) {
55
            $this->secretKey = $settings['plugin.']['tx_dpf.']['settings.']['deliverInactiveSecretKey'];
56
        }
57
    }
58
59
    /**
60
     * Returns the View Icon with link
61
     *
62
     * @param array $row Data row
63
     * @param integer $viewPage Detail View page id
64
     * @param  integer $apiPid
65
     * @param  string $insideText
66
     * @param  string $class
67
     * @return string html output
68
     */
69
    protected function getViewIcon(array $row, $pageUid, $apiPid, $insideText, $class)
70
    {
71
72
        $previewMets = BackendUtility::getViewDomain($pageUid)
73
            . '/index.php?id=' . $apiPid
74
            . '&tx_dpf[qid]=' . $row['uid']
75
            . '&tx_dpf[action]=' . $row['action'];
76
77
        if (array_key_exists('deliverInactive', $row)) {
78
            $previewMets .= '&tx_dpf[deliverInactive]=' . $row['deliverInactive'];
79
        }
80
81
        $additionalGetVars = '&tx_dlf[id]=' . urlencode($previewMets) . '&no_cache=1';
82
        $title = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('manager.tooltip.preview', 'dpf', $arguments = null);
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Utility\LocalizationUtility was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
83
        $icon = '<a href="#" data-toggle="tooltip" class="' . $class . '" onclick="' . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::viewOnClick($pageUid, $this->backPath, '', '', '', $additionalGetVars)) . '" title="' . $title . '">' .
84
                          $insideText . '</a>';
85
86
        return $icon;
87
88
    }
89
90
    /**
91
     * Renders a record list as known from the TYPO3 list module
92
     * Note: This feature is experimental!
93
     *
94
     * @param array() $arguments
95
     * @param  integer $pageUid
96
     * @param  integer $apiPid
97
     * @param  string $class
98
     * @return string the rendered record list
99
     */
100
    public function render(array $arguments, $pageUid, $apiPid, $class)
101
    {
102
103
        if ($arguments['document']) {
104
105
            // it's already a document object?
106
            if ($arguments['document'] instanceof \EWW\Dpf\Domain\Model\Document) {
107
108
                $document = $arguments['document'];
109
110
            } else if (MathUtility::canBeInterpretedAsInteger($arguments['document'])) {
111
112
                $document = $this->documentRepository->findByUid($arguments['document']);
113
114
            }
115
116
            // we found a valid document
117
            if ($document) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $document does not seem to be defined for all execution paths leading up to this point.
Loading history...
118
119
                $row['uid'] = $document->getUid();
0 ignored issues
show
Comprehensibility Best Practice introduced by
$row was never initialized. Although not strictly required by PHP, it is generally a good practice to add $row = array(); before regardless.
Loading history...
120
121
                $row['title'] = $document->getTitle();
122
123
                $row['action'] = 'preview';
124
125
            } else {
126
127
                // ok, nothing to render. So return empty content.
128
                return '';
129
130
            }
131
132
        } else if ($arguments['documentObjectIdentifier']) {
133
134
            $row['action'] = 'mets';
135
136
            $row['uid'] = $arguments['documentObjectIdentifier'];
137
138
            // pass configured API secret key parameter to enable dissemination of inactive documents
139
            if (isset($this->secretKey)) {
140
                $row['deliverInactive'] = $this->secretKey;
141
            }
142
143
        }
144
145
        $insideText = $this->renderChildren();
146
147
        $content = $this->getViewIcon($row, $pageUid, $apiPid, $insideText, $class);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $row does not seem to be defined for all execution paths leading up to this point.
Loading history...
148
149
        return $content;
150
151
    }
152
}
153