Completed
Push — master ( 7f2d14...7fc8f2 )
by Fabien
02:11
created

ModuleLoader::setModuleLanguageFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
namespace Fab\Vidi\Module;
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 Fab\Vidi\Utility\BackendUtility;
12
use TYPO3\CMS\Core\Utility\GeneralUtility;
13
use TYPO3\CMS\Extbase\Utility\ExtensionUtility;
14
use Fab\Vidi\Exception\InvalidKeyInArrayException;
15
use Fab\Vidi\Service\BackendUserPreferenceService;
16
17
/**
18
 * Service class used in other extensions to register a vidi based backend module.
19
 */
20
class ModuleLoader
21
{
22
23
    /**
24
     * Define the default main module
25
     */
26
    const DEFAULT_MAIN_MODULE = 'content';
27
28
    /**
29
     * Define the default pid
30
     */
31
    const DEFAULT_PID = 0;
32
33
    /**
34
     * The type of data being listed (which corresponds to a table name in TCA)
35
     *
36
     * @var string
37
     */
38
    protected $dataType;
39
40
    /**
41
     * @var string
42
     */
43
    protected $defaultPid;
44
45
    /**
46
     * @var bool
47
     */
48
    protected $showPageTree = false;
49
50
    /**
51
     * @var bool
52
     */
53
    protected $isShown = true;
54
55
    /**
56
     * @var string
57
     */
58
    protected $access;
59
60
    /**
61
     * @var string
62
     */
63
    protected $mainModule;
64
65
    /**
66
     * @var string
67
     */
68
    protected $position = '';
69
70
    /**
71
     * @var string
72
     */
73
    protected $icon;
74
75
    /**
76
     * @var string
77
     */
78
    protected $moduleLanguageFile;
79
80
    /**
81
     * The module key such as m1, m2.
82
     *
83
     * @var string
84
     */
85
    protected $moduleKey = 'm1';
86
87
    /**
88
     * @var string[]
89
     */
90
    protected $additionalJavaScriptFiles = [];
91
92
    /**
93
     * @var string[]
94
     */
95
    protected $additionalStyleSheetFiles = [];
96
97
    /**
98
     * @var array
99
     */
100
    protected $components = [];
101
102
    /**
103
     * @param string $dataType
104
     */
105
    public function __construct($dataType = null)
106
    {
107
        $this->dataType = $dataType;
108
109
        // Initialize components
110
        $this->components = [
111
            ModulePosition::DOC_HEADER => [
112
                ModulePosition::TOP => [
113
                    ModulePosition::LEFT => [],
114
                    ModulePosition::RIGHT => [
115
                        'Fab\Vidi\View\Button\ToolButton',
116
                    ],
117
                ],
118
                ModulePosition::BOTTOM => [
119
                    ModulePosition::LEFT => [
120
                        'Fab\Vidi\View\Button\NewButton',
121
                        'Fab\Vidi\ViewHelpers\Link\BackViewHelper',
122
                    ],
123
                    ModulePosition::RIGHT => [],
124
                ],
125
            ],
126
            ModulePosition::GRID => [
127
                ModulePosition::TOP => [
128
                    'Fab\Vidi\View\Check\PidCheck',
129
                    'Fab\Vidi\View\Check\RelationsCheck',
130
                    'Fab\Vidi\View\Tab\DataTypeTab',
131
                ],
132
                ModulePosition::BUTTONS => [
133
                    'Fab\Vidi\View\Button\EditButton',
134
                    'Fab\Vidi\View\Button\DeleteButton',
135
                ],
136
                ModulePosition::BOTTOM => [],
137
            ],
138
            ModulePosition::MENU_MASS_ACTION => [
139
                'Fab\Vidi\View\MenuItem\ExportXlsMenuItem',
140
                'Fab\Vidi\View\MenuItem\ExportXmlMenuItem',
141
                'Fab\Vidi\View\MenuItem\ExportCsvMenuItem',
142
                'Fab\Vidi\View\MenuItem\DividerMenuItem',
143
                'Fab\Vidi\View\MenuItem\MassDeleteMenuItem',
144
                #'Fab\Vidi\View\MenuItem\MassEditMenuItem',
145
            ],
146
        ];
147
    }
148
149
    /**
150
     * Tell whether a module is already registered.
151
     *
152
     * @param string $dataType
153
     * @return bool
154
     */
155
    public function isRegistered($dataType)
156
    {
157
        $internalModuleSignature = $this->getInternalModuleSignature($dataType);
158
        return !empty($GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]);
159
    }
160
161
    /**
162
     * @return array
163
     */
164
    protected function getExistingInternalConfiguration()
165
    {
166
        $internalModuleSignature = $this->getInternalModuleSignature();
167
        return is_array($GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature])
168
            ? $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]
169
            : [];
170
    }
171
172
    /**
173
     * @return array
174
     */
175
    protected function getExistingMainConfiguration()
176
    {
177
        $possibleConfiguration = $GLOBALS['TBE_MODULES']['_configuration'][$this->computeMainModule() . '_' . $this->getInternalModuleSignature()];
178
        return is_array($possibleConfiguration) ? $possibleConfiguration : [];
179
    }
180
181
    /**
182
     * @return string
183
     */
184
    protected function computeMainModule()
185
    {
186
        $existingConfiguration = $this->getExistingInternalConfiguration();
187
188
        if ($this->mainModule !== null) {
189
            $mainModule = $this->mainModule;
190
        } elseif ($existingConfiguration['mainModule']) { // existing configuration may override.
191
            $mainModule = $existingConfiguration['mainModule'];
192
        } else {
193
            $mainModule = self::DEFAULT_MAIN_MODULE; //default value.
194
        }
195
        return $mainModule;
196
    }
197
198
    /**
199
     * @return string
200
     */
201
    protected function computeDefaultPid()
202
    {
203
        $existingConfiguration = $this->getExistingInternalConfiguration();
204
205
        if ($this->defaultPid !== null) {
206
            $defaultPid = $this->defaultPid;
207
        } elseif ($existingConfiguration['defaultPid']) { // existing configuration may override.
208
            $defaultPid = $existingConfiguration['defaultPid'];
209
        } else {
210
            $defaultPid = self::DEFAULT_PID; //default value.
211
        }
212
        return $defaultPid;
213
    }
214
215
    /**
216
     * @return array
217
     */
218 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...
219
    {
220
        $additionalJavaScriptFiles = $this->additionalJavaScriptFiles;
221
222
        // Possible merge of existing javascript files.
223
        $existingConfiguration = $this->getExistingInternalConfiguration();
224
        if ($existingConfiguration['additionalJavaScriptFiles']) {
225
            $additionalJavaScriptFiles = array_merge($additionalJavaScriptFiles, $existingConfiguration['additionalJavaScriptFiles']);
226
        }
227
228
        return $additionalJavaScriptFiles;
229
    }
230
231
    /**
232
     * @return array
233
     */
234 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...
235
    {
236
        $additionalStyleSheetFiles = $this->additionalStyleSheetFiles;
237
238
        // Possible merge of existing style sheets.
239
        $existingConfiguration = $this->getExistingInternalConfiguration();
240
        if ($existingConfiguration['additionalStyleSheetFiles']) {
241
            $additionalStyleSheetFiles = array_merge($additionalStyleSheetFiles, $existingConfiguration['additionalStyleSheetFiles']);
242
        }
243
244
        return $additionalStyleSheetFiles;
245
    }
246
247
    /**
248
     * @return array
249
     */
250
    protected function computeComponents()
251
    {
252
        // We override the config in any case. See if we need more than that.
253
        return $this->components;
254
    }
255
256
    /**
257
     * Register the module in two places: core + vidi internal.
258
     *
259
     * @return void
260
     * @throws \InvalidArgumentException
261
     */
262
    public function register()
263
    {
264
        // Internal Vidi module registration.
265
        $configuration = [];
266
        $configuration['dataType'] = $this->dataType;
267
        $configuration['mainModule'] = $this->computeMainModule();
268
        $configuration['defaultPid'] = $this->computeDefaultPid();
269
        $configuration['additionalJavaScriptFiles'] = $this->computeAdditionalJavaScriptFiles();
270
        $configuration['additionalStyleSheetFiles'] = $this->computeAdditionalStyleSheetFiles();
271
        $configuration['components'] = $this->computeComponents();
272
273
        $internalModuleSignature = $this->getInternalModuleSignature();
274
        $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature] = $configuration;
275
276
        // Core module registration.
277
        // Register and displays module in the BE only if told, default is "true".
278
        if ($this->isShown) {
279
280
            $moduleConfiguration = [];
281
            #$moduleConfiguration['routeTarget'] = \Fab\Vidi\Controller\ContentController::class . '::mainAction', // what to do here?
282
            $moduleConfiguration['access'] = $this->getAccess();
283
            $moduleConfiguration['labels'] = $this->getModuleLanguageFile();
284
            $icon = $this->getIcon();
285
            if ($icon) {
286
                $moduleConfiguration['icon'] = $icon;
287
            }
288
289
            if ($this->showPageTree) {
290
                $moduleConfiguration['navigationComponentId'] = 'typo3-pagetree';
291
                $moduleConfiguration['inheritNavigationComponentFromMainModule'] = false;
292
            } else {
293
                $moduleConfiguration['inheritNavigationComponentFromMainModule'] = true;
294
            }
295
296
            ExtensionUtility::registerModule(
297
                'Fab.vidi',
298
                $this->computeMainModule(),
299
                $this->dataType . '_' . $this->moduleKey,
300
                $this->position,
301
                [
302
                    'Content' => 'index, list, delete, update, edit, copy, move, localize, sort, copyClipboard, moveClipboard',
303
                    'Tool' => 'welcome, work',
304
                    'Facet' => 'autoSuggest, autoSuggests',
305
                    'Selection' => 'edit, update, create, delete, list, show',
306
                    'UserPreferences' => 'save',
307
                    'Clipboard' => 'save, flush, show',
308
                ],
309
                $moduleConfiguration
310
            );
311
        }
312
    }
313
314
    /**
315
     * Return the module code for a BE module.
316
     *
317
     * @return string
318
     */
319
    public function getSignature()
320
    {
321
        $signature = GeneralUtility::_GP(Parameter::MODULE);
322
        $trimmedSignature = trim($signature, '/');
323
        return str_replace('/', '_', $trimmedSignature);
324
    }
325
326
    /**
327
     * Tell whether the current module is the list one.
328
     *
329
     * @return bool
330
     */
331
    public function copeWithPageTree()
332
    {
333
        return GeneralUtility::_GP(Parameter::MODULE) === 'web_VidiM1';
334
    }
335
336
    /**
337
     * Returns the current pid.
338
     *
339
     * @return bool
340
     */
341
    public function getCurrentPid()
342
    {
343
        return GeneralUtility::_GET(Parameter::PID) > 0 ? (int)GeneralUtility::_GET(Parameter::PID) : 0;
344
    }
345
346
    /**
347
     * Return the Vidi module code which is stored in TBE_MODULES_EXT
348
     *
349
     * @return string
350
     */
351
    public function getVidiModuleCode()
352
    {
353
354
        if ($this->copeWithPageTree()) {
355
            $userPreferenceKey = sprintf('Vidi_pid_%s', $this->getCurrentPid());
356
357
            if (GeneralUtility::_GP(Parameter::SUBMODULE)) {
358
                $subModuleCode = GeneralUtility::_GP(Parameter::SUBMODULE);
359
                BackendUserPreferenceService::getInstance()->set($userPreferenceKey, $subModuleCode);
360
            } else {
361
362
                $defaultModuleCode = BackendUserPreferenceService::getInstance()->get($userPreferenceKey);
363
                if (empty($defaultModuleCode)) {
364
                    $defaultModuleCode = 'VidiTtContentM1'; // hard-coded submodule
365
                    BackendUserPreferenceService::getInstance()->set($userPreferenceKey, $defaultModuleCode);
366
                }
367
368
                $vidiModules = ModuleService::getInstance()->getModulesForCurrentPid();
369
370
                if (empty($vidiModules)) {
371
                    $subModuleCode = $defaultModuleCode;
372
                } elseif (isset($vidiModules[$defaultModuleCode])) {
373
                    $subModuleCode = $defaultModuleCode;
374
                } else {
375
                    $subModuleCode = ModuleService::getInstance()->getFirstModuleForPid($this->getCurrentPid());
376
                }
377
            }
378
        } else {
379
            $moduleCode = $this->getSignature();
380
381
            // Remove first part which is separated "_"
382
            $delimiter = strpos($moduleCode, '_') + 1;
383
            $subModuleCode = substr($moduleCode, $delimiter);
384
        }
385
386
        return $subModuleCode;
387
    }
388
389
    /**
390
     * Return the module URL.
391
     *
392
     * @param array $additionalParameters
393
     * @return string
394
     */
395
    public function getModuleUrl(array $additionalParameters = [])
396
    {
397
        $moduleCode = $this->getSignature();
398
399
        // Add possible submodule if current module has page tree.
400
        if ($this->copeWithPageTree() && !isset($additionalParameters[Parameter::SUBMODULE])) {
401
            $additionalParameters[Parameter::SUBMODULE] = $this->getVidiModuleCode();
402
        }
403
404
        // And don't forget the pid!
405
        if (GeneralUtility::_GET(Parameter::PID)) {
406
            $additionalParameters[Parameter::PID] = GeneralUtility::_GET(Parameter::PID);
407
        }
408
409
        return BackendUtility::getModuleUrl($moduleCode, $additionalParameters);
410
    }
411
412
    /**
413
     * Return the parameter prefix for a BE module.
414
     *
415
     * @return string
416
     */
417
    public function getParameterPrefix()
418
    {
419
        return 'tx_vidi_' . strtolower($this->getSignature());
420
    }
421
422
    /**
423
     * Return a configuration key or the entire module configuration array if not key is given.
424
     *
425
     * @param string $key
426
     * @throws InvalidKeyInArrayException
427
     * @return mixed
428
     */
429
    public function getModuleConfiguration($key = '')
430
    {
431
432
        $vidiModuleCode = $this->getVidiModuleCode();
433
434
        // Module code must exist
435
        if (empty($GLOBALS['TBE_MODULES_EXT']['vidi'][$vidiModuleCode])) {
436
            $message = sprintf('Invalid or not existing module code "%s"', $vidiModuleCode);
437
            throw new InvalidKeyInArrayException($message, 1375092053);
438
        }
439
440
        $result = $GLOBALS['TBE_MODULES_EXT']['vidi'][$vidiModuleCode];
441
442
        if (!empty($key)) {
443
            if (isset($result[$key])) {
444
                $result = $result[$key];
445
            } else {
446
                // key must exist
447
                $message = sprintf('Invalid key configuration "%s"', $key);
448
                throw new InvalidKeyInArrayException($message, 1375092054);
449
            }
450
        }
451
        return $result;
452
    }
453
454
    /**
455
     * @param string $icon
456
     * @return $this
457
     */
458
    public function setIcon($icon)
459
    {
460
        $this->icon = $icon;
461
        return $this;
462
    }
463
464
    /**
465
     * @return string
466
     */
467 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...
468
    {
469
        $moduleConfiguration = $this->getExistingMainConfiguration();
470
471
472
        if ($this->icon) {
473
            $icon = $this->icon;
474
        } elseif ($moduleConfiguration['icon']) { // existing configuration may override.
475
            $icon = $moduleConfiguration['icon'];
476
        } else {
477
            $icon = ''; //default value.
478
        }
479
480
        return $icon;
481
    }
482
483
    /**
484
     * @param string $mainModule
485
     * @return $this
486
     */
487
    public function setMainModule($mainModule)
488
    {
489
        $this->mainModule = $mainModule;
490
        return $this;
491
    }
492
493
    /**
494
     * @return string
495
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
496
     */
497
    public function getMainModule()
498
    {
499
        if ($this->mainModule === null) {
500
            $this->mainModule = $this->getModuleConfiguration('mainModule');
501
        }
502
        return $this->mainModule;
503
    }
504
505
    /**
506
     * @param string $moduleLanguageFile
507
     * @return $this
508
     */
509
    public function setModuleLanguageFile($moduleLanguageFile)
510
    {
511
        $this->moduleLanguageFile = $moduleLanguageFile;
512
        return $this;
513
    }
514
515
    /**
516
     * @return string
517
     */
518
    protected function getModuleLanguageFile()
519
    {
520
        $moduleConfiguration = $this->getExistingMainConfiguration();
521
522
        if ($this->moduleLanguageFile) {
523
            $moduleLanguageFile = $this->moduleLanguageFile;
524
        } elseif ($moduleConfiguration['labels']) { // existing configuration may override.
525
            $moduleLanguageFile = $moduleConfiguration['labels'];
526
        }
527
        else {
528
            $moduleLanguageFile = ''; //default value.
529
        }
530
531
        return $moduleLanguageFile;
532
    }
533
534
    /**
535
     * @param string $position
536
     * @return $this
537
     */
538
    public function setPosition($position)
539
    {
540
        $this->position = $position;
541
        return $this;
542
    }
543
544
    /**
545
     * @return string
546
     */
547
    public function getPosition()
548
    {
549
        return $this->position;
550
    }
551
552
    /**
553
     * @param array $files
554
     * @return $this
555
     */
556
    public function addJavaScriptFiles(array $files)
557
    {
558
        foreach ($files as $file) {
559
            $this->additionalJavaScriptFiles[] = $file;
560
        }
561
        return $this;
562
    }
563
564
    /**
565
     * @param string $fileNameAndPath
566
     * @return $this
567
     */
568
    public function addJavaScriptFile($fileNameAndPath)
569
    {
570
        $this->additionalJavaScriptFiles[] = $fileNameAndPath;
571
        return $this;
572
    }
573
574
    /**
575
     * @param array $files
576
     * @return $this
577
     */
578
    public function addStyleSheetFiles(array $files)
579
    {
580
        foreach ($files as $file) {
581
            $this->additionalStyleSheetFiles[] = $file;
582
        }
583
        return $this;
584
    }
585
586
    /**
587
     * @param string $fileNameAndPath
588
     * @return $this
589
     */
590
    public function addStyleSheetFile($fileNameAndPath)
591
    {
592
        $this->additionalStyleSheetFiles[] = $fileNameAndPath;
593
        return $this;
594
    }
595
596
    /**
597
     * @return string
598
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
599
     */
600
    public function getDataType()
601
    {
602
        if (is_null($this->dataType)) {
603
            $this->dataType = $this->getModuleConfiguration('dataType');
604
        }
605
        return $this->dataType;
606
    }
607
608
    /**
609
     * @return array
610
     */
611
    public function getDataTypes()
612
    {
613
        $dataTypes = [];
614
        foreach ($GLOBALS['TBE_MODULES_EXT']['vidi'] as $module) {
615
            $dataTypes[] = $module['dataType'];
616
        }
617
        return $dataTypes;
618
    }
619
620
    /**
621
     * @param string $dataType
622
     * @return $this
623
     */
624
    public function setDataType($dataType)
625
    {
626
        $this->dataType = $dataType;
627
        return $this;
628
    }
629
630
    /**
631
     * @return string
632
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
633
     */
634
    public function getDefaultPid()
635
    {
636
        if (empty($this->defaultPid)) {
637
            $this->defaultPid = $this->getModuleConfiguration('defaultPid');
638
        }
639
        return $this->defaultPid;
640
    }
641
642
    /**
643
     * @param string $defaultPid
644
     * @return $this
645
     */
646
    public function setDefaultPid($defaultPid)
647
    {
648
        $this->defaultPid = $defaultPid;
649
        return $this;
650
    }
651
652
    /**
653
     * @param bool $isPageTreeShown
654
     * @return $this
655
     */
656
    public function showPageTree($isPageTreeShown)
657
    {
658
        $this->showPageTree = $isPageTreeShown;
659
        return $this;
660
    }
661
662
    /**
663
     * @param string $isShown
664
     * @return $this
665
     */
666
    public function isShown($isShown)
667
    {
668
        $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...
669
        return $this;
670
    }
671
672
    /**
673
     * @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...
674
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
675
     */
676
    public function getDocHeaderTopLeftComponents()
677
    {
678
        $configuration = $this->getModuleConfiguration();
679
        return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT];
680
    }
681
682
    /**
683
     * @param array $components
684
     * @return $this
685
     */
686
    public function setDocHeaderTopLeftComponents(array $components)
687
    {
688
        $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT] = $components;
689
        return $this;
690
    }
691
692
    /**
693
     * @param string|array $components
694
     * @return $this
695
     */
696 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...
697
    {
698
        if (is_string($components)) {
699
            $components = [$components];
700
        }
701
        $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT];
702
        $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT] = array_merge($currentComponents, $components);
703
        return $this;
704
    }
705
706
    /**
707
     * @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...
708
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
709
     */
710
    public function getDocHeaderTopRightComponents()
711
    {
712
        $configuration = $this->getModuleConfiguration();
713
        return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT];
714
    }
715
716
    /**
717
     * @param array $components
718
     * @return $this
719
     */
720
    public function setDocHeaderTopRightComponents(array $components)
721
    {
722
        $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT] = $components;
723
        return $this;
724
    }
725
726
    /**
727
     * @param string|array $components
728
     * @return $this
729
     */
730 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...
731
    {
732
        if (is_string($components)) {
733
            $components = [$components];
734
        }
735
        $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT];
736
        $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT] = array_merge($currentComponents, $components);
737
        return $this;
738
    }
739
740
    /**
741
     * @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...
742
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
743
     */
744
    public function getDocHeaderBottomLeftComponents()
745
    {
746
        $configuration = $this->getModuleConfiguration();
747
        return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT];
748
    }
749
750
    /**
751
     * @param array $components
752
     * @return $this
753
     */
754
    public function setDocHeaderBottomLeftComponents(array $components)
755
    {
756
        $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT] = $components;
757
        return $this;
758
    }
759
760
    /**
761
     * @param string|array $components
762
     * @return $this
763
     */
764 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...
765
    {
766
        if (is_string($components)) {
767
            $components = [$components];
768
        }
769
        $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT];
770
        $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT] = array_merge($currentComponents, $components);
771
        return $this;
772
    }
773
774
    /**
775
     * @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...
776
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
777
     */
778
    public function getDocHeaderBottomRightComponents()
779
    {
780
        $configuration = $this->getModuleConfiguration();
781
        return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT];
782
    }
783
784
    /**
785
     * @param array $components
786
     * @return $this
787
     */
788
    public function setDocHeaderBottomRightComponents(array $components)
789
    {
790
        $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT] = $components;
791
        return $this;
792
    }
793
794
    /**
795
     * @param string|array $components
796
     * @return $this
797
     */
798 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...
799
    {
800
        if (is_string($components)) {
801
            $components = [$components];
802
        }
803
        $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT];
804
        $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT] = array_merge($currentComponents, $components);
805
        return $this;
806
    }
807
808
    /**
809
     * @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...
810
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
811
     */
812
    public function getGridTopComponents()
813
    {
814
        $configuration = $this->getModuleConfiguration();
815
        return $configuration['components'][ModulePosition::GRID][ModulePosition::TOP];
816
    }
817
818
    /**
819
     * @param array $components
820
     * @return $this
821
     */
822
    public function setGridTopComponents(array $components)
823
    {
824
        $this->components[ModulePosition::GRID][ModulePosition::TOP] = $components;
825
        return $this;
826
    }
827
828
    /**
829
     * @param string|array $components
830
     * @return $this
831
     */
832 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...
833
    {
834
        if (is_string($components)) {
835
            $components = [$components];
836
        }
837
        $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::TOP];
838
        $this->components[ModulePosition::GRID][ModulePosition::TOP] = array_merge($currentComponents, $components);
839
        return $this;
840
    }
841
842
    /**
843
     * @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...
844
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
845
     */
846
    public function getGridBottomComponents()
847
    {
848
        $configuration = $this->getModuleConfiguration();
849
        return $configuration['components'][ModulePosition::GRID][ModulePosition::BOTTOM];
850
    }
851
852
    /**
853
     * @param array $components
854
     * @return $this
855
     */
856
    public function setGridBottomComponents(array $components)
857
    {
858
        $this->components[ModulePosition::GRID][ModulePosition::BOTTOM] = $components;
859
        return $this;
860
    }
861
862
    /**
863
     * @param string|array $components
864
     * @return $this
865
     */
866 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...
867
    {
868
        if (is_string($components)) {
869
            $components = [$components];
870
        }
871
        $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::BOTTOM];
872
        $this->components[ModulePosition::GRID][ModulePosition::BOTTOM] = array_merge($currentComponents, $components);
873
        return $this;
874
    }
875
876
    /**
877
     * @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...
878
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
879
     */
880
    public function getGridButtonsComponents()
881
    {
882
        $configuration = $this->getModuleConfiguration();
883
        return $configuration['components'][ModulePosition::GRID][ModulePosition::BUTTONS];
884
    }
885
886
    /**
887
     * @param array $components
888
     * @return $this
889
     */
890
    public function setGridButtonsComponents(array $components)
891
    {
892
        $this->components[ModulePosition::GRID][ModulePosition::BUTTONS] = $components;
893
        return $this;
894
    }
895
896
    /**
897
     * @param string|array $components
898
     * @return $this
899
     */
900 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...
901
    {
902
        if (is_string($components)) {
903
            $components = [$components];
904
        }
905
        $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::BUTTONS];
906
        $this->components[ModulePosition::GRID][ModulePosition::BUTTONS] = array_merge($components, $currentComponents);
907
        return $this;
908
    }
909
910
    /**
911
     * @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...
912
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
913
     */
914
    public function getMenuMassActionComponents()
915
    {
916
        $configuration = $this->getModuleConfiguration();
917
        return $configuration['components'][ModulePosition::MENU_MASS_ACTION];
918
    }
919
920
    /**
921
     * @param array $components
922
     * @return $this
923
     */
924
    public function setMenuMassActionComponents(array $components)
925
    {
926
        $this->components[ModulePosition::MENU_MASS_ACTION] = $components;
927
        return $this;
928
    }
929
930
    /**
931
     * @param string|array $components
932
     * @return $this
933
     */
934
    public function addMenuMassActionComponents($components)
935
    {
936
        if (is_string($components)) {
937
            $components = [$components];
938
        }
939
        $currentComponents = $this->components[ModulePosition::MENU_MASS_ACTION];
940
        $this->components[ModulePosition::MENU_MASS_ACTION] = array_merge($components, $currentComponents);
941
        return $this;
942
    }
943
944
    /**
945
     * @return string
946
     */
947 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...
948
    {
949
        $moduleConfiguration = $this->getExistingMainConfiguration();
950
951
        if ($this->access !== null) {
952
            $access = $this->access;
953
        } elseif ($moduleConfiguration['access']) { // existing configuration may override.
954
            $access = $moduleConfiguration['access'];
955
        } else {
956
            $access = Access::USER; //default value.
957
        }
958
        return $access;
959
    }
960
961
    /**
962
     * @param string $access
963
     * @return $this
964
     */
965
    public function setAccess($access)
966
    {
967
        $this->access = $access;
968
        return $this;
969
    }
970
971
    /**
972
     * @return \string[]
973
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
974
     */
975
    public function getAdditionalJavaScriptFiles()
976
    {
977
        if (empty($this->additionalJavaScriptFiles)) {
978
            $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...
979
        }
980
        return $this->additionalJavaScriptFiles;
981
    }
982
983
    /**
984
     * @return \string[]
985
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
986
     */
987
    public function getAdditionalStyleSheetFiles()
988
    {
989
        if (empty($this->additionalStyleSheetFiles)) {
990
            $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...
991
        }
992
        return $this->additionalStyleSheetFiles;
993
    }
994
995
    /**
996
     * @return array
997
     */
998
    public function getComponents()
999
    {
1000
        return $this->components;
1001
    }
1002
1003
    /**
1004
     * @param string $pluginName
1005
     * @return bool
1006
     */
1007
    public function hasPlugin($pluginName = '')
1008
    {
1009
        $parameterPrefix = $this->getParameterPrefix();
1010
        $parameters = GeneralUtility::_GET($parameterPrefix);
1011
1012
        $hasPlugin = !empty($parameters['plugins']) && is_array($parameters['plugins']);
1013
        if ($hasPlugin && $pluginName) {
1014
            $hasPlugin = in_array($pluginName, $parameters['plugins']);
1015
        }
1016
        return $hasPlugin;
1017
    }
1018
1019
    /**
1020
     * Compute the internal module code
1021
     *
1022
     * @param null|string $dataType
1023
     * @return string
1024
     */
1025
    protected function getInternalModuleSignature($dataType = null)
1026
    {
1027
        if ($dataType === null) {
1028
            $dataType = $this->dataType;
1029
        }
1030
        $subModuleName = $dataType . '_' . $this->moduleKey;
1031
        return 'Vidi' . GeneralUtility::underscoredToUpperCamelCase($subModuleName);
1032
    }
1033
1034
}
1035