Completed
Push — master ( 3ff228...f62711 )
by Fabien
03:35
created

ModuleLoader::computeAdditionalJavaScriptFiles()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 12
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 12
loc 12
rs 9.4285
cc 2
eloc 6
nc 2
nop 0
1
<?php
2
namespace Fab\Vidi\Module;
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\Backend\Utility\BackendUtility;
18
use TYPO3\CMS\Core\Utility\GeneralUtility;
19
use TYPO3\CMS\Extbase\Utility\ExtensionUtility;
20
use Fab\Vidi\Exception\InvalidKeyInArrayException;
21
use Fab\Vidi\Service\BackendUserPreferenceService;
22
23
/**
24
 * Service class used in other extensions to register a vidi based backend module.
25
 */
26
class ModuleLoader
27
{
28
29
    /**
30
     * Define the default main module
31
     */
32
    const DEFAULT_MAIN_MODULE = 'content';
33
34
    /**
35
     * Define the default pid
36
     */
37
    const DEFAULT_PID = 0;
38
39
    /**
40
     * The type of data being listed (which corresponds to a table name in TCA)
41
     *
42
     * @var string
43
     */
44
    protected $dataType;
45
46
    /**
47
     * @var string
48
     */
49
    protected $defaultPid;
50
51
    /**
52
     * @var bool
53
     */
54
    protected $showPageTree = false;
55
56
    /**
57
     * @var bool
58
     */
59
    protected $isShown = true;
60
61
    /**
62
     * @var string
63
     */
64
    protected $access;
65
66
    /**
67
     * @var string
68
     */
69
    protected $mainModule;
70
71
    /**
72
     * @var string
73
     */
74
    protected $position = '';
75
76
    /**
77
     * @var string
78
     */
79
    protected $icon;
80
81
    /**
82
     * @var string
83
     */
84
    protected $moduleLanguageFile;
85
86
    /**
87
     * The module key such as m1, m2.
88
     *
89
     * @var string
90
     */
91
    protected $moduleKey = 'm1';
92
93
    /**
94
     * @var string[]
95
     */
96
    protected $additionalJavaScriptFiles = [];
97
98
    /**
99
     * @var string[]
100
     */
101
    protected $additionalStyleSheetFiles = [];
102
103
    /**
104
     * @var array
105
     */
106
    protected $components = [];
107
108
    /**
109
     * @param string $dataType
110
     */
111
    public function __construct($dataType = null)
112
    {
113
        $this->dataType = $dataType;
114
115
        // Initialize components
116
        $this->components = [
117
            ModulePosition::DOC_HEADER => [
118
                ModulePosition::TOP => [
119
                    ModulePosition::LEFT => [],
120
                    ModulePosition::RIGHT => [
121
                        'Fab\Vidi\View\Button\ToolButton',
122
                    ],
123
                ],
124
                ModulePosition::BOTTOM => [
125
                    ModulePosition::LEFT => [
126
                        'Fab\Vidi\View\Button\NewButton',
127
                        'Fab\Vidi\ViewHelpers\Link\BackViewHelper',
128
                    ],
129
                    ModulePosition::RIGHT => [],
130
                ],
131
            ],
132
            ModulePosition::GRID => [
133
                ModulePosition::TOP => [
134
                    'Fab\Vidi\View\Check\PidCheck',
135
                    'Fab\Vidi\View\Check\RelationsCheck',
136
                    'Fab\Vidi\View\Tab\DataTypeTab',
137
                ],
138
                ModulePosition::BUTTONS => [
139
                    'Fab\Vidi\View\Button\EditButton',
140
                    'Fab\Vidi\View\Button\DeleteButton',
141
                ],
142
                ModulePosition::BOTTOM => [],
143
            ],
144
            ModulePosition::MENU_MASS_ACTION => [
145
                'Fab\Vidi\View\MenuItem\ExportXlsMenuItem',
146
                'Fab\Vidi\View\MenuItem\ExportXmlMenuItem',
147
                'Fab\Vidi\View\MenuItem\ExportCsvMenuItem',
148
                'Fab\Vidi\View\MenuItem\DividerMenuItem',
149
                'Fab\Vidi\View\MenuItem\MassDeleteMenuItem',
150
                #'Fab\Vidi\View\MenuItem\MassEditMenuItem',
151
            ],
152
        ];
153
    }
154
155
    /**
156
     * Tell whether a module is already registered.
157
     *
158
     * @param string $dataType
159
     * @return bool
160
     */
161
    public function isRegistered($dataType)
0 ignored issues
show
Coding Style introduced by
isRegistered 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...
162
    {
163
        $internalModuleSignature = $this->getInternalModuleSignature($dataType);
164
        return !empty($GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]);
165
    }
166
167
    /**
168
     * @return array
169
     */
170
    protected function getExistingInternalConfiguration()
0 ignored issues
show
Coding Style introduced by
getExistingInternalConfiguration 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...
171
    {
172
        $internalModuleSignature = $this->getInternalModuleSignature();
173
        return is_array($GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature])
174
            ? $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]
175
            : [];
176
    }
177
178
    /**
179
     * @return array
180
     */
181
    protected function getExistingMainConfiguration()
0 ignored issues
show
Coding Style introduced by
getExistingMainConfiguration 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...
182
    {
183
        $possibleConfiguration = $GLOBALS['TBE_MODULES']['_configuration']['Vidi_' . $this->getInternalModuleSignature()];
184
        return is_array($possibleConfiguration) ? $possibleConfiguration : [];
185
    }
186
187
    /**
188
     * @return string
189
     */
190
    protected function computeMainModule()
191
    {
192
        $existingConfiguration = $this->getExistingInternalConfiguration();
193
194
        if ($this->mainModule !== null) {
195
            $mainModule = $this->mainModule;
196
        } elseif ($existingConfiguration['mainModule']) { // existing configuration may override.
197
            $mainModule = $existingConfiguration['mainModule'];
198
        } else {
199
            $mainModule = self::DEFAULT_MAIN_MODULE; //default value.
200
        }
201
        return $mainModule;
202
    }
203
204
    /**
205
     * @return string
206
     */
207
    protected function computeDefaultPid()
208
    {
209
        $existingConfiguration = $this->getExistingInternalConfiguration();
210
211
        if ($this->defaultPid !== null) {
212
            $defaultPid = $this->defaultPid;
213
        } elseif ($existingConfiguration['defaultPid']) { // existing configuration may override.
214
            $defaultPid = $existingConfiguration['defaultPid'];
215
        } else {
216
            $defaultPid = self::DEFAULT_PID; //default value.
217
        }
218
        return $defaultPid;
219
    }
220
221
    /**
222
     * @return array
223
     */
224 View Code Duplication
    protected function computeAdditionalJavaScriptFiles()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
225
    {
226
        $additionalJavaScriptFiles = $this->additionalJavaScriptFiles;
227
228
        // Possible merge of existing javascript files.
229
        $existingConfiguration = $this->getExistingInternalConfiguration();
230
        if ($existingConfiguration['additionalJavaScriptFiles']) {
231
            $additionalJavaScriptFiles = array_merge($additionalJavaScriptFiles, $existingConfiguration['additionalJavaScriptFiles']);
232
        }
233
234
        return $additionalJavaScriptFiles;
235
    }
236
237
    /**
238
     * @return array
239
     */
240 View Code Duplication
    protected function computeAdditionalStyleSheetFiles()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
241
    {
242
        $additionalStyleSheetFiles = $this->additionalStyleSheetFiles;
243
244
        // Possible merge of existing style sheets.
245
        $existingConfiguration = $this->getExistingInternalConfiguration();
246
        if ($existingConfiguration['additionalStyleSheetFiles']) {
247
            $additionalStyleSheetFiles = array_merge($additionalStyleSheetFiles, $existingConfiguration['additionalStyleSheetFiles']);
248
        }
249
250
        return $additionalStyleSheetFiles;
251
    }
252
253
    /**
254
     * @return array
255
     */
256
    protected function computeComponents()
257
    {
258
        // We override the config in any case. See if we need more than that.
259
        return $this->components;
260
    }
261
262
    /**
263
     * Register the module in two places: core + vidi internal.
264
     *
265
     * @return void
266
     * @throws \InvalidArgumentException
267
     */
268
    public function register()
0 ignored issues
show
Coding Style introduced by
register 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...
269
    {
270
        // Internal Vidi module registration.
271
        $configuration = [];
272
        $configuration['dataType'] = $this->dataType;
273
        $configuration['mainModule'] = $this->computeMainModule();
274
        $configuration['defaultPid'] = $this->computeDefaultPid();
275
        $configuration['additionalJavaScriptFiles'] = $this->computeAdditionalJavaScriptFiles();
276
        $configuration['additionalStyleSheetFiles'] = $this->computeAdditionalStyleSheetFiles();
277
        $configuration['components'] = $this->computeComponents();
278
279
        $internalModuleSignature = $this->getInternalModuleSignature();
280
        $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature] = $configuration;
281
282
        // Core module registration.
283
        // Register and displays module in the BE only if told, default is "true".
284
        if ($this->isShown) {
285
286
            $moduleConfiguration = [];
287
            #$moduleConfiguration['routeTarget'] = \Fab\Vidi\Controller\ContentController::class . '::mainAction', // what to do here?
0 ignored issues
show
Unused Code Comprehensibility introduced by
44% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
288
            $moduleConfiguration['access'] = $this->getAccess();
289
            $moduleConfiguration['labels'] = $this->getModuleLanguageFile();
290
            $icon = $this->getIcon();
291
            if ($icon) {
292
                $moduleConfiguration['icon'] = $icon;
293
            }
294
295
            if ($this->showPageTree) {
296
                $moduleConfiguration['navigationComponentId'] = 'typo3-pagetree';
297
                $moduleConfiguration['inheritNavigationComponentFromMainModule'] = false;
298
            } else {
299
                $moduleConfiguration['inheritNavigationComponentFromMainModule'] = true;
300
            }
301
302
            ExtensionUtility::registerModule(
303
                'Fab.vidi',
304
                $this->mainModule,
305
                $this->dataType . '_' . $this->moduleKey,
306
                $this->position,
307
                [
308
                    'Content' => 'index, list, delete, update, edit, copy, move, localize, sort, copyClipboard, moveClipboard',
309
                    'Tool' => 'welcome, work',
310
                    'Facet' => 'autoSuggest, autoSuggests',
311
                    'Selection' => 'edit, update, create, delete, list, show',
312
                    'UserPreferences' => 'save',
313
                    'Clipboard' => 'save, flush, show',
314
                ],
315
                $moduleConfiguration
316
            );
317
        }
318
    }
319
320
    /**
321
     * Return the module code for a BE module.
322
     *
323
     * @return string
324
     */
325
    public function getSignature()
326
    {
327
        return GeneralUtility::_GP(Parameter::MODULE);
328
    }
329
330
    /**
331
     * Tell whether the current module is the list one.
332
     *
333
     * @return bool
334
     */
335
    public function copeWithPageTree()
336
    {
337
        return GeneralUtility::_GP(Parameter::MODULE) === 'web_VidiM1';
338
    }
339
340
    /**
341
     * Returns the current pid.
342
     *
343
     * @return bool
344
     */
345
    public function getCurrentPid()
346
    {
347
        return GeneralUtility::_GET(Parameter::PID) > 0 ? (int)GeneralUtility::_GET(Parameter::PID) : 0;
348
    }
349
350
    /**
351
     * Return the Vidi module code which is stored in TBE_MODULES_EXT
352
     *
353
     * @return string
354
     */
355
    public function getVidiModuleCode()
356
    {
357
358
        if ($this->copeWithPageTree()) {
359
            $userPreferenceKey = sprintf('Vidi_pid_%s', $this->getCurrentPid());
360
361
            if (GeneralUtility::_GP(Parameter::SUBMODULE)) {
362
                $subModuleCode = GeneralUtility::_GP(Parameter::SUBMODULE);
363
                BackendUserPreferenceService::getInstance()->set($userPreferenceKey, $subModuleCode);
364
            } else {
365
366
                $defaultModuleCode = BackendUserPreferenceService::getInstance()->get($userPreferenceKey);
367
                if (empty($defaultModuleCode)) {
368
                    $defaultModuleCode = 'VidiTtContentM1'; // hard-coded submodule
369
                    BackendUserPreferenceService::getInstance()->set($userPreferenceKey, $defaultModuleCode);
370
                }
371
372
                $vidiModules = ModuleService::getInstance()->getModulesForCurrentPid();
373
374
                if (empty($vidiModules)) {
375
                    $subModuleCode = $defaultModuleCode;
376
                } elseif (isset($vidiModules[$defaultModuleCode])) {
377
                    $subModuleCode = $defaultModuleCode;
378
                } else {
379
                    $subModuleCode = ModuleService::getInstance()->getFirstModuleForPid($this->getCurrentPid());
380
                }
381
            }
382
        } else {
383
            $moduleCode = $this->getSignature();
384
385
            // Remove first part which is separated "_"
386
            $delimiter = strpos($moduleCode, '_') + 1;
387
            $subModuleCode = substr($moduleCode, $delimiter);
388
        }
389
390
        return $subModuleCode;
391
    }
392
393
    /**
394
     * Return the module URL.
395
     *
396
     * @param array $additionalParameters
397
     * @param bool $absoluteUrl
398
     * @return string
399
     */
400
    public function getModuleUrl(array $additionalParameters = [], $absoluteUrl = false)
401
    {
402
        $moduleCode = $this->getSignature();
403
404
        // Add possible submodule if current module has page tree.
405
        if ($this->copeWithPageTree() && !isset($additionalParameters[Parameter::SUBMODULE])) {
406
            $additionalParameters[Parameter::SUBMODULE] = $this->getVidiModuleCode();
407
        }
408
409
        // And don't forget the pid!
410
        if (GeneralUtility::_GET(Parameter::PID)) {
411
            $additionalParameters[Parameter::PID] = GeneralUtility::_GET(Parameter::PID);
412
        }
413
414
        $moduleUrl = BackendUtility::getModuleUrl($moduleCode, $additionalParameters, false, $absoluteUrl);
415
        return $moduleUrl;
416
    }
417
418
    /**
419
     * Return the module absolute URL.
420
     *
421
     * @param array $additionalParameters
422
     * @return string
423
     */
424
    public function getModuleAbsoluteUrl(array $additionalParameters = [])
425
    {
426
        return $this->getModuleUrl($additionalParameters, true);
427
    }
428
429
    /**
430
     * Return the parameter prefix for a BE module.
431
     *
432
     * @return string
433
     */
434
    public function getParameterPrefix()
435
    {
436
        return 'tx_vidi_' . strtolower($this->getSignature());
437
    }
438
439
    /**
440
     * Return a configuration key or the entire module configuration array if not key is given.
441
     *
442
     * @param string $key
443
     * @throws InvalidKeyInArrayException
444
     * @return mixed
445
     */
446
    public function getModuleConfiguration($key = '')
0 ignored issues
show
Coding Style introduced by
getModuleConfiguration 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...
447
    {
448
449
        $vidiModuleCode = $this->getVidiModuleCode();
450
451
        // Module code must exist
452
        if (empty($GLOBALS['TBE_MODULES_EXT']['vidi'][$vidiModuleCode])) {
453
            $message = sprintf('Invalid or not existing module code "%s"', $vidiModuleCode);
454
            throw new InvalidKeyInArrayException($message, 1375092053);
455
        }
456
457
        $result = $GLOBALS['TBE_MODULES_EXT']['vidi'][$vidiModuleCode];
458
459
        if (!empty($key)) {
460
            if (isset($result[$key])) {
461
                $result = $result[$key];
462
            } else {
463
                // key must exist
464
                $message = sprintf('Invalid key configuration "%s"', $key);
465
                throw new InvalidKeyInArrayException($message, 1375092054);
466
            }
467
        }
468
        return $result;
469
    }
470
471
    /**
472
     * @param string $icon
473
     * @return $this
474
     */
475
    public function setIcon($icon)
476
    {
477
        $this->icon = $icon;
478
        return $this;
479
    }
480
481
    /**
482
     * @return string
483
     */
484 View Code Duplication
    protected function getIcon()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
485
    {
486
        $moduleConfiguration = $this->getExistingMainConfiguration();
487
488
489
        if ($this->icon) {
490
            $icon = $this->icon;
491
        } elseif ($moduleConfiguration['icon']) { // existing configuration may override.
492
            $icon = $moduleConfiguration['icon'];
493
        } else {
494
            $icon = ''; //default value.
495
        }
496
497
        return $icon;
498
    }
499
500
    /**
501
     * @param string $mainModule
502
     * @return $this
503
     */
504
    public function setMainModule($mainModule)
505
    {
506
        $this->mainModule = $mainModule;
507
        return $this;
508
    }
509
510
    /**
511
     * @return string
512
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
513
     */
514
    public function getMainModule()
515
    {
516
        if ($this->mainModule === null) {
517
            $this->mainModule = $this->getModuleConfiguration('mainModule');
518
        }
519
        return $this->mainModule;
520
    }
521
522
    /**
523
     * @param string $moduleLanguageFile
524
     * @return $this
525
     */
526
    public function setModuleLanguageFile($moduleLanguageFile)
527
    {
528
        $this->moduleLanguageFile = $moduleLanguageFile;
529
        return $this;
530
    }
531
532
    /**
533
     * @return string
534
     */
535 View Code Duplication
    protected function getModuleLanguageFile()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
536
    {
537
        $moduleConfiguration = $this->getExistingMainConfiguration();
538
539
        if ($this->moduleLanguageFile !== null) {
540
            $moduleLanguageFile = $this->moduleLanguageFile;
541
        } elseif ($moduleConfiguration['moduleLanguageFile']) { // existing configuration may override.
542
            $moduleLanguageFile = $moduleConfiguration['moduleLanguageFile'];
543
        } else {
544
            $moduleLanguageFile = 'LLL:EXT:vidi/Resources/Private/Language/locallang_module.xlf'; //default value.
545
        }
546
        return $moduleLanguageFile;
547
    }
548
549
    /**
550
     * @param string $position
551
     * @return $this
552
     */
553
    public function setPosition($position)
554
    {
555
        $this->position = $position;
556
        return $this;
557
    }
558
559
    /**
560
     * @return string
561
     */
562
    public function getPosition()
563
    {
564
        return $this->position;
565
    }
566
567
    /**
568
     * @param array $files
569
     * @return $this
570
     */
571
    public function addJavaScriptFiles(array $files)
572
    {
573
        foreach ($files as $file) {
574
            $this->additionalJavaScriptFiles[] = $file;
575
        }
576
        return $this;
577
    }
578
579
    /**
580
     * @param string $fileNameAndPath
581
     * @return $this
582
     */
583
    public function addJavaScriptFile($fileNameAndPath)
584
    {
585
        $this->additionalJavaScriptFiles[] = $fileNameAndPath;
586
        return $this;
587
    }
588
589
    /**
590
     * @param array $files
591
     * @return $this
592
     */
593
    public function addStyleSheetFiles(array $files)
594
    {
595
        foreach ($files as $file) {
596
            $this->additionalStyleSheetFiles[] = $file;
597
        }
598
        return $this;
599
    }
600
601
    /**
602
     * @param string $fileNameAndPath
603
     * @return $this
604
     */
605
    public function addStyleSheetFile($fileNameAndPath)
606
    {
607
        $this->additionalStyleSheetFiles[] = $fileNameAndPath;
608
        return $this;
609
    }
610
611
    /**
612
     * @return string
613
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
614
     */
615
    public function getDataType()
616
    {
617
        if (is_null($this->dataType)) {
618
            $this->dataType = $this->getModuleConfiguration('dataType');
619
        }
620
        return $this->dataType;
621
    }
622
623
    /**
624
     * @return array
625
     */
626
    public function getDataTypes()
0 ignored issues
show
Coding Style introduced by
getDataTypes 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...
627
    {
628
        $dataTypes = [];
629
        foreach ($GLOBALS['TBE_MODULES_EXT']['vidi'] as $module) {
630
            $dataTypes[] = $module['dataType'];
631
        }
632
        return $dataTypes;
633
    }
634
635
    /**
636
     * @param string $dataType
637
     * @return $this
638
     */
639
    public function setDataType($dataType)
640
    {
641
        $this->dataType = $dataType;
642
        return $this;
643
    }
644
645
    /**
646
     * @return string
647
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
648
     */
649
    public function getDefaultPid()
650
    {
651
        if (empty($this->defaultPid)) {
652
            $this->defaultPid = $this->getModuleConfiguration('defaultPid');
653
        }
654
        return $this->defaultPid;
655
    }
656
657
    /**
658
     * @param string $defaultPid
659
     * @return $this
660
     */
661
    public function setDefaultPid($defaultPid)
662
    {
663
        $this->defaultPid = $defaultPid;
664
        return $this;
665
    }
666
667
    /**
668
     * @param bool $isPageTreeShown
669
     * @return $this
670
     */
671
    public function showPageTree($isPageTreeShown)
672
    {
673
        $this->showPageTree = $isPageTreeShown;
674
        return $this;
675
    }
676
677
    /**
678
     * @param string $isShown
679
     * @return $this
680
     */
681
    public function isShown($isShown)
682
    {
683
        $this->isShown = $isShown;
0 ignored issues
show
Documentation Bug introduced by
The property $isShown was declared of type boolean, but $isShown is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
684
        return $this;
685
    }
686
687
    /**
688
     * @return $array
0 ignored issues
show
Documentation introduced by
The doc-type $array could not be parsed: Unknown type name "$array" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
689
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
690
     */
691
    public function getDocHeaderTopLeftComponents()
692
    {
693
        $configuration = $this->getModuleConfiguration();
694
        return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT];
695
    }
696
697
    /**
698
     * @param array $components
699
     * @return $this
700
     */
701
    public function setDocHeaderTopLeftComponents(array $components)
702
    {
703
        $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT] = $components;
704
        return $this;
705
    }
706
707
    /**
708
     * @param string|array $components
709
     * @return $this
710
     */
711 View Code Duplication
    public function addDocHeaderTopLeftComponents($components)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
712
    {
713
        if (is_string($components)) {
714
            $components = [$components];
715
        }
716
        $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT];
717
        $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT] = array_merge($currentComponents, $components);
718
        return $this;
719
    }
720
721
    /**
722
     * @return $array
0 ignored issues
show
Documentation introduced by
The doc-type $array could not be parsed: Unknown type name "$array" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
723
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
724
     */
725
    public function getDocHeaderTopRightComponents()
726
    {
727
        $configuration = $this->getModuleConfiguration();
728
        return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT];
729
    }
730
731
    /**
732
     * @param array $components
733
     * @return $this
734
     */
735
    public function setDocHeaderTopRightComponents(array $components)
736
    {
737
        $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT] = $components;
738
        return $this;
739
    }
740
741
    /**
742
     * @param string|array $components
743
     * @return $this
744
     */
745 View Code Duplication
    public function addDocHeaderTopRightComponents($components)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
746
    {
747
        if (is_string($components)) {
748
            $components = [$components];
749
        }
750
        $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT];
751
        $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT] = array_merge($currentComponents, $components);
752
        return $this;
753
    }
754
755
    /**
756
     * @return $array
0 ignored issues
show
Documentation introduced by
The doc-type $array could not be parsed: Unknown type name "$array" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
757
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
758
     */
759
    public function getDocHeaderBottomLeftComponents()
760
    {
761
        $configuration = $this->getModuleConfiguration();
762
        return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT];
763
    }
764
765
    /**
766
     * @param array $components
767
     * @return $this
768
     */
769
    public function setDocHeaderBottomLeftComponents(array $components)
770
    {
771
        $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT] = $components;
772
        return $this;
773
    }
774
775
    /**
776
     * @param string|array $components
777
     * @return $this
778
     */
779 View Code Duplication
    public function addDocHeaderBottomLeftComponents($components)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
780
    {
781
        if (is_string($components)) {
782
            $components = [$components];
783
        }
784
        $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT];
785
        $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT] = array_merge($currentComponents, $components);
786
        return $this;
787
    }
788
789
    /**
790
     * @return $array
0 ignored issues
show
Documentation introduced by
The doc-type $array could not be parsed: Unknown type name "$array" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
791
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
792
     */
793
    public function getDocHeaderBottomRightComponents()
794
    {
795
        $configuration = $this->getModuleConfiguration();
796
        return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT];
797
    }
798
799
    /**
800
     * @param array $components
801
     * @return $this
802
     */
803
    public function setDocHeaderBottomRightComponents(array $components)
804
    {
805
        $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT] = $components;
806
        return $this;
807
    }
808
809
    /**
810
     * @param string|array $components
811
     * @return $this
812
     */
813 View Code Duplication
    public function addDocHeaderBottomRightComponents($components)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
814
    {
815
        if (is_string($components)) {
816
            $components = [$components];
817
        }
818
        $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT];
819
        $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT] = array_merge($currentComponents, $components);
820
        return $this;
821
    }
822
823
    /**
824
     * @return $array
0 ignored issues
show
Documentation introduced by
The doc-type $array could not be parsed: Unknown type name "$array" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
825
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
826
     */
827
    public function getGridTopComponents()
828
    {
829
        $configuration = $this->getModuleConfiguration();
830
        return $configuration['components'][ModulePosition::GRID][ModulePosition::TOP];
831
    }
832
833
    /**
834
     * @param array $components
835
     * @return $this
836
     */
837
    public function setGridTopComponents(array $components)
838
    {
839
        $this->components[ModulePosition::GRID][ModulePosition::TOP] = $components;
840
        return $this;
841
    }
842
843
    /**
844
     * @param string|array $components
845
     * @return $this
846
     */
847 View Code Duplication
    public function addGridTopComponents($components)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
848
    {
849
        if (is_string($components)) {
850
            $components = [$components];
851
        }
852
        $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::TOP];
853
        $this->components[ModulePosition::GRID][ModulePosition::TOP] = array_merge($currentComponents, $components);
854
        return $this;
855
    }
856
857
    /**
858
     * @return $array
0 ignored issues
show
Documentation introduced by
The doc-type $array could not be parsed: Unknown type name "$array" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
859
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
860
     */
861
    public function getGridBottomComponents()
862
    {
863
        $configuration = $this->getModuleConfiguration();
864
        return $configuration['components'][ModulePosition::GRID][ModulePosition::BOTTOM];
865
    }
866
867
    /**
868
     * @param array $components
869
     * @return $this
870
     */
871
    public function setGridBottomComponents(array $components)
872
    {
873
        $this->components[ModulePosition::GRID][ModulePosition::BOTTOM] = $components;
874
        return $this;
875
    }
876
877
    /**
878
     * @param string|array $components
879
     * @return $this
880
     */
881 View Code Duplication
    public function addGridBottomComponents($components)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
882
    {
883
        if (is_string($components)) {
884
            $components = [$components];
885
        }
886
        $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::BOTTOM];
887
        $this->components[ModulePosition::GRID][ModulePosition::BOTTOM] = array_merge($currentComponents, $components);
888
        return $this;
889
    }
890
891
    /**
892
     * @return $array
0 ignored issues
show
Documentation introduced by
The doc-type $array could not be parsed: Unknown type name "$array" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
893
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
894
     */
895
    public function getGridButtonsComponents()
896
    {
897
        $configuration = $this->getModuleConfiguration();
898
        return $configuration['components'][ModulePosition::GRID][ModulePosition::BUTTONS];
899
    }
900
901
    /**
902
     * @param array $components
903
     * @return $this
904
     */
905
    public function setGridButtonsComponents(array $components)
906
    {
907
        $this->components[ModulePosition::GRID][ModulePosition::BUTTONS] = $components;
908
        return $this;
909
    }
910
911
    /**
912
     * @param string|array $components
913
     * @return $this
914
     */
915 View Code Duplication
    public function addGridButtonsComponents($components)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
916
    {
917
        if (is_string($components)) {
918
            $components = [$components];
919
        }
920
        $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::BUTTONS];
921
        $this->components[ModulePosition::GRID][ModulePosition::BUTTONS] = array_merge($currentComponents, $components);
922
        return $this;
923
    }
924
925
    /**
926
     * @return $array
0 ignored issues
show
Documentation introduced by
The doc-type $array could not be parsed: Unknown type name "$array" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
927
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
928
     */
929
    public function getMenuMassActionComponents()
930
    {
931
        $configuration = $this->getModuleConfiguration();
932
        return $configuration['components'][ModulePosition::MENU_MASS_ACTION];
933
    }
934
935
    /**
936
     * @param array $components
937
     * @return $this
938
     */
939
    public function setMenuMassActionComponents(array $components)
940
    {
941
        $this->components[ModulePosition::MENU_MASS_ACTION] = $components;
942
        return $this;
943
    }
944
945
    /**
946
     * @param string|array $components
947
     * @return $this
948
     */
949
    public function addMenuMassActionComponents($components)
950
    {
951
        if (is_string($components)) {
952
            $components = [$components];
953
        }
954
        $currentComponents = $this->components[ModulePosition::MENU_MASS_ACTION];
955
        $this->components[ModulePosition::MENU_MASS_ACTION] = array_merge($currentComponents, $components);
956
        return $this;
957
    }
958
959
    /**
960
     * @return string
961
     */
962 View Code Duplication
    protected function getAccess()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
963
    {
964
        $moduleConfiguration = $this->getExistingMainConfiguration();
965
966
        if ($this->access !== null) {
967
            $access = $this->access;
968
        } elseif ($moduleConfiguration['access']) { // existing configuration may override.
969
            $access = $moduleConfiguration['access'];
970
        } else {
971
            $access = Access::USER; //default value.
972
        }
973
        return $access;
974
    }
975
976
    /**
977
     * @param string $access
978
     * @return $this
979
     */
980
    public function setAccess($access)
981
    {
982
        $this->access = $access;
983
        return $this;
984
    }
985
986
    /**
987
     * @return \string[]
988
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
989
     */
990
    public function getAdditionalJavaScriptFiles()
991
    {
992
        if (empty($this->additionalJavaScriptFiles)) {
993
            $this->additionalJavaScriptFiles = $this->getModuleConfiguration('additionalJavaScriptFiles');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getModuleConfigur...tionalJavaScriptFiles') of type * is incompatible with the declared type array<integer,string> of property $additionalJavaScriptFiles.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
994
        }
995
        return $this->additionalJavaScriptFiles;
996
    }
997
998
    /**
999
     * @return \string[]
1000
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
1001
     */
1002
    public function getAdditionalStyleSheetFiles()
1003
    {
1004
        if (empty($this->additionalStyleSheetFiles)) {
1005
            $this->additionalStyleSheetFiles = $this->getModuleConfiguration('additionalStyleSheetFiles');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getModuleConfigur...tionalStyleSheetFiles') of type * is incompatible with the declared type array<integer,string> of property $additionalStyleSheetFiles.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
1006
        }
1007
        return $this->additionalStyleSheetFiles;
1008
    }
1009
1010
    /**
1011
     * @return array
1012
     */
1013
    public function getComponents()
1014
    {
1015
        return $this->components;
1016
    }
1017
1018
    /**
1019
     * @param string $pluginName
1020
     * @return bool
1021
     */
1022
    public function hasPlugin($pluginName = '')
1023
    {
1024
        $parameterPrefix = $this->getParameterPrefix();
1025
        $parameters = GeneralUtility::_GET($parameterPrefix);
1026
1027
        $hasPlugin = !empty($parameters['plugins']) && is_array($parameters['plugins']);
1028
        if ($hasPlugin && $pluginName) {
1029
            $hasPlugin = in_array($pluginName, $parameters['plugins']);
1030
        }
1031
        return $hasPlugin;
1032
    }
1033
1034
    /**
1035
     * Compute the internal module code
1036
     *
1037
     * @param null|string $dataType
1038
     * @return string
1039
     */
1040
    protected function getInternalModuleSignature($dataType = null)
1041
    {
1042
        if ($dataType === null) {
1043
            $dataType = $this->dataType;
1044
        }
1045
        $subModuleName = $dataType . '_' . $this->moduleKey;
1046
        return 'Vidi' . GeneralUtility::underscoredToUpperCamelCase($subModuleName);
1047
    }
1048
1049
}
1050