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