forceStaticTSFilesBeforeAllTSTemplates()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
namespace Qbus\Qbtools\Utility;
3
4
use TYPO3\CMS\Core\TypoScript\TemplateService;
5
use TYPO3\CMS\Core\Utility\GeneralUtility;
6
7
/**
8
 * TypoScriptManagementUtility
9
 *
10
 * @author Benjamin Franzke <[email protected]>
11
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
12
 */
13
class TypoScriptManagementUtility
14
{
15
    /**
16
     * @var array
17
     */
18
    private static $staticTypoScript = array();
19
20
    /*
21
     * @var bool
22
     */
23
    private static $includeStaticTemplateFilesBeforeAllStaticTemplates = false;
24
25
26
    /**
27
     * @param  string $path
28
     * @return void
29
     */
30
    public static function addStaticTypoScript($path)
31
    {
32
        if (!in_array($path, self::$staticTypoScript)) {
33
            array_push(self::$staticTypoScript, $path);
34
        }
35
    }
36
37
    /**
38
     * @param  array $paths
39
     * @return void
40
     */
41
    public static function addStaticTypoScripts($paths)
42
    {
43
        foreach ($paths as $path) {
44
            self::addStaticTypoScript($path);
45
        }
46
    }
47
48
    /**
49
     * @param bool $enable
50
     */
51
    public static function forceStaticTSFilesBeforeAllTSTemplates($enable = true)
52
    {
53
        self::$includeStaticTemplateFilesBeforeAllStaticTemplates = $enable;
54
    }
55
56
    /**
57
     * Includes static template from extensions
58
     *
59
     * @param array           $params
60
     * @param TemplateService $pObj
61
     * @return void
62
     */
63
    public function preprocessIncludeStaticTypoScriptSources(array &$params, TemplateService $pObj)
0 ignored issues
show
Unused Code introduced by
The parameter $pObj is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

63
    public function preprocessIncludeStaticTypoScriptSources(array &$params, /** @scrutinizer ignore-unused */ TemplateService $pObj)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
64
    {
65
        if (isset($params['row']['root']) && $params['row']['root']) {
66
            $existing = GeneralUtility::trimExplode(',', $params['row']['include_static_file']);
67
            $staticTemplates = array_merge($existing, self::$staticTypoScript);
68
            $params['row']['include_static_file'] = implode(',', array_unique($staticTemplates));
69
        }
70
71
        if (self::$includeStaticTemplateFilesBeforeAllStaticTemplates) {
72
            /* Enfore "Static Template Files from TYPO3 Extensions:" to be
73
             * "Include before all static templates if root flag is set".
74
             * So that our typoscript can override typoscript from other extensions "ext_typoscript_setup.txt" */
75
            $params['row']['static_file_mode'] = 3;
76
        }
77
    }
78
}
79