Completed
Push — master ( 161673...ceaaa1 )
by Fabien
02:33
created

ModuleLoader::addJavaScriptFile()   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::class,
116
                    ],
117
                ],
118
                ModulePosition::BOTTOM => [
119
                    ModulePosition::LEFT => [
120
                        \Fab\Vidi\View\Button\NewButton::class,
121
                        \Fab\Vidi\ViewHelpers\Link\BackViewHelper::class,
122
                    ],
123
                    ModulePosition::RIGHT => [],
124
                ],
125
            ],
126
            ModulePosition::GRID => [
127
                ModulePosition::TOP => [
128
                    \Fab\Vidi\View\Check\PidCheck::class,
129
                    \Fab\Vidi\View\Check\RelationsCheck::class,
130
                    #\Fab\Vidi\View\Tab\DataTypeTab::class,
131
                ],
132
                ModulePosition::BUTTONS => [
133
                    \Fab\Vidi\View\Button\EditButton::class,
134
                    \Fab\Vidi\View\Button\DeleteButton::class,
135
                ],
136
                ModulePosition::BOTTOM => [],
137
            ],
138
            ModulePosition::MENU_MASS_ACTION => [
139
                \Fab\Vidi\View\MenuItem\ExportXlsMenuItem::class,
140
                \Fab\Vidi\View\MenuItem\ExportXmlMenuItem::class,
141
                \Fab\Vidi\View\MenuItem\ExportCsvMenuItem::class,
142
                \Fab\Vidi\View\MenuItem\DividerMenuItem::class,
143
                \Fab\Vidi\View\MenuItem\MassDeleteMenuItem::class,
144
                #\Fab\Vidi\View\MenuItem\MassEditMenuItem::class,
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): bool
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(): array
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(): array
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(): string
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(): string
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(): array
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(): array
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(): array
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(): void
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/CMS/Backend/PageTree/PageTreeElement';
291
                $moduleConfiguration['inheritNavigationComponentFromMainModule'] = true;
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(): string
320
    {
321
        $signature = GeneralUtility::_GP(Parameter::MODULE);
322
        $trimmedSignature = trim($signature, '/');
323
        return str_replace('/', '_', $trimmedSignature);
324
    }
325
326
    /**
327
     * Returns the current pid.
328
     *
329
     * @return bool
330
     */
331
    public function getCurrentPid(): bool
332
    {
333
        return GeneralUtility::_GET(Parameter::PID) > 0 ? (int)GeneralUtility::_GET(Parameter::PID) : 0;
334
    }
335
336
    /**
337
     * Return the module URL.
338
     *
339
     * @param array $additionalParameters
340
     * @return string
341
     */
342
    public function getModuleUrl(array $additionalParameters = []): string
343
    {
344
        $moduleCode = $this->getSignature();
345
346
        // And don't forget the pid!
347
        if (GeneralUtility::_GET(Parameter::PID)) {
348
            $additionalParameters[Parameter::PID] = GeneralUtility::_GET(Parameter::PID);
349
        }
350
351
        return BackendUtility::getModuleUrl($moduleCode, $additionalParameters);
352
    }
353
354
    /**
355
     * Return the parameter prefix for a BE module.
356
     *
357
     * @return string
358
     */
359
    public function getParameterPrefix(): string
360
    {
361
        return 'tx_vidi_' . strtolower($this->getSignature());
362
    }
363
364
    /**
365
     * Return a configuration key or the entire module configuration array if not key is given.
366
     *
367
     * @param string $key
368
     * @throws InvalidKeyInArrayException
369
     * @return mixed
370
     */
371
    public function getModuleConfiguration($key = '')
372
    {
373
374
        $vidiModuleCode = $this->getSignature();
375
376
        // Module code must exist
377
        if (empty($GLOBALS['TBE_MODULES_EXT']['vidi'][$vidiModuleCode])) {
378
            $message = sprintf('Invalid or not existing module code "%s"', $vidiModuleCode);
379
            throw new InvalidKeyInArrayException($message, 1375092053);
380
        }
381
382
        $result = $GLOBALS['TBE_MODULES_EXT']['vidi'][$vidiModuleCode];
383
384
        if (!empty($key)) {
385
            if (isset($result[$key])) {
386
                $result = $result[$key];
387
            } else {
388
                // key must exist
389
                $message = sprintf('Invalid key configuration "%s"', $key);
390
                throw new InvalidKeyInArrayException($message, 1375092054);
391
            }
392
        }
393
        return $result;
394
    }
395
396
    /**
397
     * @param string $icon
398
     * @return $this
399
     */
400
    public function setIcon($icon): self
401
    {
402
        $this->icon = $icon;
403
        return $this;
404
    }
405
406
    /**
407
     * @return string
408
     */
409 View Code Duplication
    protected function getIcon(): string
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...
410
    {
411
        $moduleConfiguration = $this->getExistingMainConfiguration();
412
413
414
        if ($this->icon) {
415
            $icon = $this->icon;
416
        } elseif ($moduleConfiguration['icon']) { // existing configuration may override.
417
            $icon = $moduleConfiguration['icon'];
418
        } else {
419
            $icon = ''; //default value.
420
        }
421
422
        return $icon;
423
    }
424
425
    /**
426
     * @param string $mainModule
427
     * @return $this
428
     */
429
    public function setMainModule($mainModule): self
430
    {
431
        $this->mainModule = $mainModule;
432
        return $this;
433
    }
434
435
    /**
436
     * @return string
437
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
438
     */
439
    public function getMainModule(): string
440
    {
441
        if ($this->mainModule === null) {
442
            $this->mainModule = $this->getModuleConfiguration('mainModule');
443
        }
444
        return $this->mainModule;
445
    }
446
447
    /**
448
     * @param string $moduleLanguageFile
449
     * @return $this
450
     */
451
    public function setModuleLanguageFile($moduleLanguageFile): self
452
    {
453
        $this->moduleLanguageFile = $moduleLanguageFile;
454
        return $this;
455
    }
456
457
    /**
458
     * @param string $component
459
     * @return $this
460
     */
461
    public function removeComponentFromDocHeader(string $component): self
462
    {
463
        foreach ($this->components[ModulePosition::DOC_HEADER] as $verticalPosition => $docHeaders) {
464
            foreach ($docHeaders as $horizontalPosition => $docHeader) {
465
466
                $index = array_search($component, $docHeader, true);
467
                if ($index !== false) {
468
                    // $verticalPosition: top or bottom
469
                    // $horizontalPosition: left or right
470
                    unset($this->components[ModulePosition::DOC_HEADER][$verticalPosition][$horizontalPosition][$index]);
471
                }
472
            }
473
        }
474
        return $this;
475
    }
476
477
    /**
478
     * @param string $component
479
     * @return bool
480
     */
481
    public function hasComponentInDocHeader(string $component): bool
482
    {
483
        foreach ($this->getModuleConfiguration('components')[ModulePosition::DOC_HEADER] as $verticalPosition => $docHeaders) {
484
            foreach ($docHeaders as $horizontalPosition => $docHeader) {
485
486
                $index = array_search($component, $docHeader, true);
487
                if ($index !== false) {
488
                    return true;
489
                }
490
            }
491
        }
492
        return false;
493
    }
494
495
    /**
496
     * @return string
497
     */
498
    protected function getModuleLanguageFile(): string
499
    {
500
        $moduleConfiguration = $this->getExistingMainConfiguration();
501
502
        if ($this->moduleLanguageFile) {
503
            $moduleLanguageFile = $this->moduleLanguageFile;
504
        } elseif ($moduleConfiguration['labels']) { // existing configuration may override.
505
            $moduleLanguageFile = $moduleConfiguration['labels'];
506
        }
507
        else {
508
            $moduleLanguageFile = ''; //default value.
509
        }
510
511
        return $moduleLanguageFile;
512
    }
513
514
    /**
515
     * @param string $position
516
     * @return $this
517
     */
518
    public function setPosition($position): self
519
    {
520
        $this->position = $position;
521
        return $this;
522
    }
523
524
    /**
525
     * @return string
526
     */
527
    public function getPosition(): string
528
    {
529
        return $this->position;
530
    }
531
532
    /**
533
     * @param array $files
534
     * @return $this
535
     */
536
    public function addJavaScriptFiles(array $files): self
537
    {
538
        foreach ($files as $file) {
539
            $this->additionalJavaScriptFiles[] = $file;
540
        }
541
        return $this;
542
    }
543
544
    /**
545
     * @param string $fileNameAndPath
546
     * @return $this
547
     */
548
    public function addJavaScriptFile($fileNameAndPath): self
549
    {
550
        $this->additionalJavaScriptFiles[] = $fileNameAndPath;
551
        return $this;
552
    }
553
554
    /**
555
     * @param array $files
556
     * @return $this
557
     */
558
    public function addStyleSheetFiles(array $files): self
559
    {
560
        foreach ($files as $file) {
561
            $this->additionalStyleSheetFiles[] = $file;
562
        }
563
        return $this;
564
    }
565
566
    /**
567
     * @param string $fileNameAndPath
568
     * @return $this
569
     */
570
    public function addStyleSheetFile($fileNameAndPath): self
571
    {
572
        $this->additionalStyleSheetFiles[] = $fileNameAndPath;
573
        return $this;
574
    }
575
576
    /**
577
     * @return string
578
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
579
     */
580
    public function getDataType(): string
581
    {
582
        if ($this->dataType === null) {
583
            $this->dataType = $this->getModuleConfiguration('dataType');
584
        }
585
        return $this->dataType;
586
    }
587
588
    /**
589
     * @return array
590
     */
591
    public function getDataTypes(): array
592
    {
593
        $dataTypes = [];
594
        foreach ($GLOBALS['TBE_MODULES_EXT']['vidi'] as $module) {
595
            $dataTypes[] = $module['dataType'];
596
        }
597
        return $dataTypes;
598
    }
599
600
    /**
601
     * @param string $dataType
602
     * @return $this
603
     */
604
    public function setDataType($dataType): self
605
    {
606
        $this->dataType = $dataType;
607
        return $this;
608
    }
609
610
    /**
611
     * @return string
612
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
613
     */
614
    public function getDefaultPid(): string
615
    {
616
        if (empty($this->defaultPid)) {
617
            $this->defaultPid = $this->getModuleConfiguration('defaultPid');
618
        }
619
        return $this->defaultPid;
620
    }
621
622
    /**
623
     * @param string $defaultPid
624
     * @return $this
625
     */
626
    public function setDefaultPid($defaultPid): self
627
    {
628
        $this->defaultPid = $defaultPid;
629
        return $this;
630
    }
631
632
    /**
633
     * @param bool $isPageTreeShown
634
     * @return $this
635
     */
636
    public function showPageTree($isPageTreeShown): self
637
    {
638
        $this->showPageTree = $isPageTreeShown;
639
        return $this;
640
    }
641
642
    /**
643
     * @param string $isShown
644
     * @return $this
645
     */
646
    public function isShown($isShown): self
647
    {
648
        $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...
649
        return $this;
650
    }
651
652
    /**
653
     * @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...
654
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
655
     */
656
    public function getDocHeaderTopLeftComponents()
657
    {
658
        $configuration = $this->getModuleConfiguration();
659
        return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT];
660
    }
661
662
    /**
663
     * @param array $components
664
     * @return $this
665
     */
666
    public function setDocHeaderTopLeftComponents(array $components): self
667
    {
668
        $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT] = $components;
669
        return $this;
670
    }
671
672
    /**
673
     * @param string|array $components
674
     * @return $this
675
     */
676 View Code Duplication
    public function addDocHeaderTopLeftComponents($components): self
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...
677
    {
678
        if (is_string($components)) {
679
            $components = [$components];
680
        }
681
        $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT];
682
        $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT] = array_merge($currentComponents, $components);
683
        return $this;
684
    }
685
686
    /**
687
     * @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...
688
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
689
     */
690
    public function getDocHeaderTopRightComponents()
691
    {
692
        $configuration = $this->getModuleConfiguration();
693
        return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT];
694
    }
695
696
    /**
697
     * @param array $components
698
     * @return $this
699
     */
700
    public function setDocHeaderTopRightComponents(array $components): self
701
    {
702
        $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT] = $components;
703
        return $this;
704
    }
705
706
    /**
707
     * @param string|array $components
708
     * @return $this
709
     */
710 View Code Duplication
    public function addDocHeaderTopRightComponents($components): self
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...
711
    {
712
        if (is_string($components)) {
713
            $components = [$components];
714
        }
715
        $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT];
716
        $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT] = array_merge($currentComponents, $components);
717
        return $this;
718
    }
719
720
    /**
721
     * @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...
722
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
723
     */
724
    public function getDocHeaderBottomLeftComponents()
725
    {
726
        $configuration = $this->getModuleConfiguration();
727
        return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT];
728
    }
729
730
    /**
731
     * @param array $components
732
     * @return $this
733
     */
734
    public function setDocHeaderBottomLeftComponents(array $components): self
735
    {
736
        $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT] = $components;
737
        return $this;
738
    }
739
740
    /**
741
     * @param string|array $components
742
     * @return $this
743
     */
744 View Code Duplication
    public function addDocHeaderBottomLeftComponents($components): self
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...
745
    {
746
        if (is_string($components)) {
747
            $components = [$components];
748
        }
749
        $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT];
750
        $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT] = array_merge($currentComponents, $components);
751
        return $this;
752
    }
753
754
    /**
755
     * @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...
756
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
757
     */
758
    public function getDocHeaderBottomRightComponents()
759
    {
760
        $configuration = $this->getModuleConfiguration();
761
        return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT];
762
    }
763
764
    /**
765
     * @param array $components
766
     * @return $this
767
     */
768
    public function setDocHeaderBottomRightComponents(array $components): self
769
    {
770
        $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT] = $components;
771
        return $this;
772
    }
773
774
    /**
775
     * @param string|array $components
776
     * @return $this
777
     */
778 View Code Duplication
    public function addDocHeaderBottomRightComponents($components): self
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...
779
    {
780
        if (is_string($components)) {
781
            $components = [$components];
782
        }
783
        $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT];
784
        $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT] = array_merge($currentComponents, $components);
785
        return $this;
786
    }
787
788
    /**
789
     * @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...
790
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
791
     */
792
    public function getGridTopComponents()
793
    {
794
        $configuration = $this->getModuleConfiguration();
795
        return $configuration['components'][ModulePosition::GRID][ModulePosition::TOP];
796
    }
797
798
    /**
799
     * @param array $components
800
     * @return $this
801
     */
802
    public function setGridTopComponents(array $components): self
803
    {
804
        $this->components[ModulePosition::GRID][ModulePosition::TOP] = $components;
805
        return $this;
806
    }
807
808
    /**
809
     * @param string|array $components
810
     * @return $this
811
     */
812 View Code Duplication
    public function addGridTopComponents($components): self
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...
813
    {
814
        if (is_string($components)) {
815
            $components = [$components];
816
        }
817
        $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::TOP];
818
        $this->components[ModulePosition::GRID][ModulePosition::TOP] = array_merge($currentComponents, $components);
819
        return $this;
820
    }
821
822
    /**
823
     * @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...
824
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
825
     */
826
    public function getGridBottomComponents()
827
    {
828
        $configuration = $this->getModuleConfiguration();
829
        return $configuration['components'][ModulePosition::GRID][ModulePosition::BOTTOM];
830
    }
831
832
    /**
833
     * @param array $components
834
     * @return $this
835
     */
836
    public function setGridBottomComponents(array $components): self
837
    {
838
        $this->components[ModulePosition::GRID][ModulePosition::BOTTOM] = $components;
839
        return $this;
840
    }
841
842
    /**
843
     * @param string|array $components
844
     * @return $this
845
     */
846 View Code Duplication
    public function addGridBottomComponents($components): self
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...
847
    {
848
        if (is_string($components)) {
849
            $components = [$components];
850
        }
851
        $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::BOTTOM];
852
        $this->components[ModulePosition::GRID][ModulePosition::BOTTOM] = array_merge($currentComponents, $components);
853
        return $this;
854
    }
855
856
    /**
857
     * @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...
858
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
859
     */
860
    public function getGridButtonsComponents()
861
    {
862
        $configuration = $this->getModuleConfiguration();
863
        return $configuration['components'][ModulePosition::GRID][ModulePosition::BUTTONS];
864
    }
865
866
    /**
867
     * @param array $components
868
     * @return $this
869
     */
870
    public function setGridButtonsComponents(array $components): self
871
    {
872
        $this->components[ModulePosition::GRID][ModulePosition::BUTTONS] = $components;
873
        return $this;
874
    }
875
876
    /**
877
     * @param string|array $components
878
     * @return $this
879
     */
880 View Code Duplication
    public function addGridButtonsComponents($components): self
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...
881
    {
882
        if (is_string($components)) {
883
            $components = [$components];
884
        }
885
        $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::BUTTONS];
886
        $this->components[ModulePosition::GRID][ModulePosition::BUTTONS] = array_merge($components, $currentComponents);
887
        return $this;
888
    }
889
890
    /**
891
     * @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...
892
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
893
     */
894
    public function getMenuMassActionComponents()
895
    {
896
        $configuration = $this->getModuleConfiguration();
897
        return $configuration['components'][ModulePosition::MENU_MASS_ACTION];
898
    }
899
900
    /**
901
     * @param array $components
902
     * @return $this
903
     */
904
    public function setMenuMassActionComponents(array $components): self
905
    {
906
        $this->components[ModulePosition::MENU_MASS_ACTION] = $components;
907
        return $this;
908
    }
909
910
    /**
911
     * @param string|array $components
912
     * @return $this
913
     */
914
    public function addMenuMassActionComponents($components): self
915
    {
916
        if (is_string($components)) {
917
            $components = [$components];
918
        }
919
        $currentComponents = $this->components[ModulePosition::MENU_MASS_ACTION];
920
        $this->components[ModulePosition::MENU_MASS_ACTION] = array_merge($components, $currentComponents);
921
        return $this;
922
    }
923
924
    /**
925
     * @return string
926
     */
927 View Code Duplication
    protected function getAccess(): string
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...
928
    {
929
        $moduleConfiguration = $this->getExistingMainConfiguration();
930
931
        if ($this->access !== null) {
932
            $access = $this->access;
933
        } elseif ($moduleConfiguration['access']) { // existing configuration may override.
934
            $access = $moduleConfiguration['access'];
935
        } else {
936
            $access = Access::USER; //default value.
937
        }
938
        return $access;
939
    }
940
941
    /**
942
     * @param string $access
943
     * @return $this
944
     */
945
    public function setAccess($access): self
946
    {
947
        $this->access = $access;
948
        return $this;
949
    }
950
951
    /**
952
     * @return \string[]
953
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
954
     */
955
    public function getAdditionalJavaScriptFiles(): array
956
    {
957
        if (empty($this->additionalJavaScriptFiles)) {
958
            $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...
959
        }
960
        return $this->additionalJavaScriptFiles;
961
    }
962
963
    /**
964
     * @return \string[]
965
     * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException
966
     */
967
    public function getAdditionalStyleSheetFiles(): array
968
    {
969
        if (empty($this->additionalStyleSheetFiles)) {
970
            $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...
971
        }
972
        return $this->additionalStyleSheetFiles;
973
    }
974
975
    /**
976
     * @return array
977
     */
978
    public function getComponents(): array
979
    {
980
        return $this->components;
981
    }
982
983
    /**
984
     * @param string $pluginName
985
     * @return bool
986
     */
987
    public function hasPlugin($pluginName = ''): bool
988
    {
989
        $parameterPrefix = $this->getParameterPrefix();
990
        $parameters = GeneralUtility::_GET($parameterPrefix);
991
992
        $hasPlugin = !empty($parameters['plugins']) && is_array($parameters['plugins']);
993
        if ($hasPlugin && $pluginName) {
994
            $hasPlugin = in_array($pluginName, $parameters['plugins']);
995
        }
996
        return $hasPlugin;
997
    }
998
999
    /**
1000
     * Compute the internal module code
1001
     *
1002
     * @param null|string $dataType
1003
     * @return string
1004
     */
1005
    protected function getInternalModuleSignature($dataType = null): string
1006
    {
1007
        // Else we forge the module signature
1008
        if ($dataType === null) {
1009
            $dataType = $this->dataType;
1010
        }
1011
        $subModuleName = $dataType . '_' . $this->moduleKey;
1012
1013
        $mainModule = $this->mainModule ? : self::DEFAULT_MAIN_MODULE;
1014
        return $mainModule . '_Vidi' . GeneralUtility::underscoredToUpperCamelCase($subModuleName);
1015
    }
1016
1017
}
1018