Passed
Pull Request — master (#108)
by Ralf
02:08
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
22
class PreviewViewHelper extends AbstractBackendViewHelper
23
{
24
25
    /**
26
     * @var \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...
27
     * @inject
28
     */
29
    protected $configurationManager;
30
31
    /**
32
     * documentRepository
33
     *
34
     * @var \EWW\Dpf\Domain\Repository\DocumentRepository
35
     * @inject
36
     */
37
    protected $documentRepository;
38
39
    /**
40
     * Secret API key for delivering inactive documents.
41
     * @var string
42
     */
43
    private $secretKey;
44
45
    /**
46
     * Initialize secret key from plugin TYPOScript configuration.
47
     */
48
    public function initialize() {
49
        parent::initialize();
50
51
        $settings = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS);
0 ignored issues
show
Bug introduced by
The type EWW\Dpf\ViewHelpers\Link...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...
52
53
        if (isset($settings['plugin.']['tx_dpf.']['settings.']['deliverInactiveSecretKey'])) {
54
            $this->secretKey = $settings['plugin.']['tx_dpf.']['settings.']['deliverInactiveSecretKey'];
55
        }
56
    }
57
58
    /**
59
     * Returns the View Icon with link
60
     *
61
     * @param array $row Data row
62
     * @param integer $viewPage Detail View page id
63
     * @param  integer $apiPid
64
     * @param  string $insideText
65
     * @param  string $class
66
     * @return string html output
67
     */
68
    protected function getViewIcon(array $row, $pageUid, $apiPid, $insideText, $class)
69
    {
70
71
        $previewMets = BackendUtility::getViewDomain($pageUid)
72
            . '/index.php?id=' . $apiPid
73
            . '&tx_dpf[qid]=' . $row['uid']
74
            . '&tx_dpf[action]=' . $row['action'];
75
76
        if (array_key_exists('deliverInactive', $row)) {
77
            $previewMets .= '&tx_dpf[deliverInactive]=' . $row['deliverInactive'];
78
        }
79
80
        $additionalGetVars = '&tx_dlf[id]=' . urlencode($previewMets) . '&no_cache=1';
81
        $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...
82
        $icon = '<a href="#" data-toggle="tooltip" class="' . $class . '" onclick="' . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::viewOnClick($pageUid, $this->backPath, '', '', '', $additionalGetVars)) . '" title="' . $title . '">' .
83
                          $insideText . '</a>';
84
85
        return $icon;
86
87
    }
88
89
    /**
90
     * Renders a record list as known from the TYPO3 list module
91
     * Note: This feature is experimental!
92
     *
93
     * @param array() $arguments
94
     * @param  integer $pageUid
95
     * @param  integer $apiPid
96
     * @param  string $class
97
     * @return string the rendered record list
98
     */
99
    public function render(array $arguments, $pageUid, $apiPid, $class)
100
    {
101
102
        if ($arguments['document']) {
103
104
            // it's already a document object?
105
            if ($arguments['document'] instanceof \EWW\Dpf\Domain\Model\Document) {
106
107
                $document = $arguments['document'];
108
109
            } else if (MathUtility::canBeInterpretedAsInteger($arguments['document'])) {
110
111
                $document = $this->documentRepository->findByUid($arguments['document']);
112
113
            }
114
115
            // we found a valid document
116
            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...
117
118
                $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...
119
120
                $row['title'] = $document->getTitle();
121
122
                $row['action'] = 'preview';
123
124
            } else {
125
126
                // ok, nothing to render. So return empty content.
127
                return '';
128
129
            }
130
131
        } else if ($arguments['documentObjectIdentifier']) {
132
133
            $row['action'] = 'mets';
134
135
            $row['uid'] = $arguments['documentObjectIdentifier'];
136
137
            // pass configured API secret key parameter to enable dissemination of inactive documents
138
            if (isset($this->secretKey)) {
139
                $row['deliverInactive'] = $this->secretKey;
140
            }
141
142
        }
143
144
        $insideText = $this->renderChildren();
145
146
        $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...
147
148
        return $content;
149
150
    }
151
}
152