Completed
Push — master ( bcb9f9...99ab38 )
by Fabien
03:17
created

ExtensionManager   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 0
loc 99
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B renderDataTypes() 0 59 3
B getDataTypes() 0 20 7
1
<?php
2
namespace Fab\Vidi\Backend;
3
4
/*
5
 * This file is part of the Fab/Vidi project under GPLv2 or later.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.md file that was distributed with this source code.
9
 */
10
11
use TYPO3\CMS\Core\Utility\GeneralUtility;
12
use Fab\Vidi\Configuration\ConfigurationUtility;
13
14
/**
15
 * Display custom fields in the Extension Manager.
16
 */
17
class ExtensionManager
18
{
19
20
    /**
21
     * @var array
22
     */
23
    protected $excludedContentTypes = array('pages', 'pages_language_overlay', 'tx_rtehtmlarea_acronym');
24
25
    /**
26
     * Display a message to the Extension Manager whether the configuration is OK or KO.
27
     *
28
     * @param array $params
29
     * @param \TYPO3\CMS\Core\TypoScript\ConfigurationForm $tsObj
30
     * @return string
31
     */
32
    public function renderDataTypes(&$params, &$tsObj)
0 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed.

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

Loading history...
Unused Code introduced by
The parameter $tsObj is not used and could be removed.

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

Loading history...
33
    {
34
35
        $configuration = ConfigurationUtility::getInstance()->getConfiguration();
36
        $selectedDataTypes = GeneralUtility::trimExplode(',', $configuration['data_types']);
37
        $options = '';
38
        foreach ($this->getDataTypes() as $dataType) {
39
            $checked = '';
40
41
            if (in_array($dataType, $selectedDataTypes)) {
42
                $checked = 'checked="checked"';
43
            }
44
            $options .= sprintf(
45
                '<li><label><input type="checkbox" class="fieldDataType" value="%s" %s /> %s</label></li>',
46
                $dataType,
47
                $checked,
48
                $dataType
49
            );
50
        }
51
52
        $menu = sprintf('<ul class="list-unstyled" style="margin-top: 10px;">%s</ul>', $options);
53
54
        // Assemble final output.
55
        $output = <<<EOF
56
            <div class="form-group form-group-dashed>
57
                <div class="form-control-wrap">
58
59
				    <div class="typo3-tstemplate-ceditor-row" id="userTS-dataTypes">
60
                    <script type="text/javascript">
61
                        (function($) {
62
                            $(function() {
63
64
                                // Handler which will concatenate selected data types.
65
                                $('.fieldDataType').change(function() {
66
67
                                    var dataTypes = $('#fieldDataTypes').val();
68
                                    var currentValue = $(this).val();
69
70
                                    // In any case remove item
71
                                    var expression = new RegExp(', *' + currentValue, 'i');
72
                                    dataTypes = dataTypes.replace(expression, '');
73
                                    $('#fieldDataTypes').val(dataTypes);
74
75
                                    // Append new data type at the end if checked.
76
                                    if ($(this).is(':checked')) {
77
                                        $('#fieldDataTypes').val(dataTypes + ', ' + currentValue);
78
                                    }
79
                                });
80
                            });
81
                        })(jQuery);
82
                    </script>
83
					<input type="text" class="form-control" id="fieldDataTypes" name="tx_extensionmanager_tools_extensionmanagerextensionmanager[config][data_types][value]" value="{$configuration['data_types']}" />
84
				</div>
85
                $menu
86
            </div>
87
EOF;
88
89
        return $output;
90
    }
91
92
    /**
93
     * @return array
94
     */
95
    public function getDataTypes()
96
    {
97
98
        $dataTypes = [];
99
100
        if (is_array($GLOBALS['TCA'])) {
101
            foreach ($GLOBALS['TCA'] as $contentType => $tca) {
102
                if (!in_array($contentType, $this->excludedContentTypes)
103
                    && isset($GLOBALS['TCA'][$contentType]['ctrl']['label'])
104
                    && (
105
                        !isset($GLOBALS['TCA'][$contentType]['ctrl']['hideTable'])
106
                        || true !== (bool)$GLOBALS['TCA'][$contentType]['ctrl']['hideTable']
107
                    )
108
                ) {
109
                    $dataTypes[] = $contentType;
110
                }
111
            }
112
        }
113
        return $dataTypes;
114
    }
115
}
116