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

FormResultCompiler::getBackendUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace Fab\Media\Override\Backend\Form;
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\Media\Module\VidiModule;
18
use TYPO3\CMS\Backend\Utility\BackendUtility;
19
20
/**
21
 * Class FormResultCompiler
22
 */
23
class FormResultCompiler extends \TYPO3\CMS\Backend\Form\FormResultCompiler
24
{
25
26
    /**
27
     * JavaScript bottom code
28
     *
29
     * @param string $formname The identification of the form on the page.
30
     * @return string A section with JavaScript - if $update is FALSE, embedded in <script></script>
31
     */
32
    protected function JSbottom($formname = 'forms[0]')
33
    {
34
35
        $out = parent::JSbottom($formname);
36
37
        $enableMediaFilePicker = (bool)$this->getBackendUser()->getTSConfigVal('options.vidi.enableMediaFilePicker');
38
        if ($enableMediaFilePicker) {
39
40
            $pageRenderer = $this->getPageRenderer();
41
            $pageRenderer->loadRequireJsModule('TYPO3/CMS/Media/MediaFormEngine', 'function(MediaFormEngine) {
42
            MediaFormEngine.vidiModuleUrl = \'' . BackendUtility::getModuleUrl(VidiModule::getSignature()) . '\';
43
            MediaFormEngine.vidiModulePrefix = \'' . VidiModule::getParameterPrefix() . '\';
44
        }');
45
        }
46
47
        return $out;
48
    }
49
50
    /**
51
     * Returns an instance of the current Backend User.
52
     *
53
     * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
54
     */
55
    protected function getBackendUser()
0 ignored issues
show
Coding Style introduced by
getBackendUser uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
56
    {
57
        return $GLOBALS['BE_USER'];
58
    }
59
}
60