Completed
Push — master ( 0e9113...bfde6b )
by Fabien
03:08
created

FilePickerPlugin::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
namespace Fab\Media\View\Plugin;
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 Fab\Vidi\View\AbstractComponentView;
18
use Fab\Media\Utility\Path;
19
use TYPO3\CMS\Core\Page\PageRenderer;
20
use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22
/**
23
 * View which renders content for file picker plugin.
24
 */
25
class FilePickerPlugin extends AbstractComponentView
26
{
27
28
    /**
29
     * Renders a hidden link for file picker.
30
     *
31
     * @return string
32
     */
33
    public function render()
34
    {
35
36
        if ($this->getModuleLoader()->hasPlugin('filePicker')) {
37
            $this->loadRequireJsCode();
38
        };
39
        return '';
40
    }
41
42
    /**
43
     * @return void
44
     */
45
    protected function loadRequireJsCode()
46
    {
47
        $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
48
49
        $configuration['paths']['Fab/Media'] = '../typo3conf/ext/media/Resources/Public/JavaScript';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$configuration was never initialized. Although not strictly required by PHP, it is generally a good practice to add $configuration = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
50
        $pageRenderer->addRequireJsConfiguration($configuration);
51
        $pageRenderer->loadRequireJsModule('Fab/Media/PluginFilePicker');
52
    }
53
54
}
55