addColumnButtonAction()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 34
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 18
c 0
b 0
f 0
nc 2
nop 8
dl 0
loc 34
rs 9.6666

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace Spryker\Shared\GuiTable\Configuration\Builder;
9
10
use ArrayObject;
11
use Generated\Shared\Transfer\DateRangeGuiTableFilterTypeOptionsTransfer;
12
use Generated\Shared\Transfer\GuiTableBatchActionOptionsTransfer;
13
use Generated\Shared\Transfer\GuiTableBatchActionsConfigurationTransfer;
14
use Generated\Shared\Transfer\GuiTableBatchActionTransfer;
15
use Generated\Shared\Transfer\GuiTableColumnConfigurationTransfer;
16
use Generated\Shared\Transfer\GuiTableColumnConfiguratorConfigurationTransfer;
17
use Generated\Shared\Transfer\GuiTableConfigurationTransfer;
18
use Generated\Shared\Transfer\GuiTableDataSourceConfigurationTransfer;
19
use Generated\Shared\Transfer\GuiTableEditableButtonTransfer;
20
use Generated\Shared\Transfer\GuiTableEditableConfigurationTransfer;
21
use Generated\Shared\Transfer\GuiTableEditableCreateConfigurationTransfer;
22
use Generated\Shared\Transfer\GuiTableEditableDataErrorTransfer;
23
use Generated\Shared\Transfer\GuiTableEditableInitialDataTransfer;
24
use Generated\Shared\Transfer\GuiTableEditableUpdateConfigurationTransfer;
25
use Generated\Shared\Transfer\GuiTableEditableUrlTransfer;
26
use Generated\Shared\Transfer\GuiTableFiltersConfigurationTransfer;
27
use Generated\Shared\Transfer\GuiTableFilterTransfer;
28
use Generated\Shared\Transfer\GuiTableItemSelectionConfigurationTransfer;
29
use Generated\Shared\Transfer\GuiTablePaginationConfigurationTransfer;
30
use Generated\Shared\Transfer\GuiTableRowActionOptionsTransfer;
31
use Generated\Shared\Transfer\GuiTableRowActionsConfigurationTransfer;
32
use Generated\Shared\Transfer\GuiTableRowActionTransfer;
33
use Generated\Shared\Transfer\GuiTableSearchConfigurationTransfer;
34
use Generated\Shared\Transfer\GuiTableTitleConfigurationTransfer;
35
use Generated\Shared\Transfer\GuiTableTotalConfigurationTransfer;
36
use Generated\Shared\Transfer\OptionSelectGuiTableFilterTypeOptionsTransfer;
37
use Generated\Shared\Transfer\SelectGuiTableFilterTypeOptionsTransfer;
38
use Spryker\Shared\GuiTable\Exception\InvalidConfigurationException;
39
use Spryker\Shared\GuiTable\Exception\RowActionNotFoundException;
40
41
class GuiTableConfigurationBuilder implements GuiTableConfigurationBuilderInterface
42
{
43
    /**
44
     * @see https://angular.io/api/common/DatePipe for details.
45
     *
46
     * @var string
47
     */
48
    protected const DEFAULT_UI_DATE_FORMAT = 'dd.MM.y';
49
50
    /**
51
     * @var string
52
     */
53
    protected const DEFAULT_COLUMN_BUTTON_ACTION_VARIANT = 'outline';
54
55
    /**
56
     * @var string
57
     */
58
    protected const DEFAULT_COLUMN_BUTTON_ACTION_SIZE = 'sm';
59
60
    /**
61
     * @var string
62
     */
63
    protected const DEFAULT_MODAL_OK_BUTTON_VARIANT = 'primary';
64
65
    /**
66
     * @var string
67
     */
68
    protected const DEFAULT_CHIP_MAX_WIDTH = '220px';
69
70
    /**
71
     * @var array<\Generated\Shared\Transfer\GuiTableColumnConfigurationTransfer>
72
     */
73
    protected array $columns = [];
74
75
    /**
76
     * @var array<\Generated\Shared\Transfer\GuiTableColumnConfigurationTransfer>
77
     */
78
    protected array $editableColumns = [];
79
80
    /**
81
     * @var string|null
82
     */
83
    protected ?string $title = null;
84
85
    /**
86
     * @var array<\Generated\Shared\Transfer\GuiTableFilterTransfer>
87
     */
88
    protected array $filters = [];
89
90
    /**
91
     * @var array<\Generated\Shared\Transfer\GuiTableRowActionTransfer>
92
     */
93
    protected array $rowActions = [];
94
95
    /**
96
     * @var string|null
97
     */
98
    protected ?string $rowOnClickIdAction = null;
99
100
    /**
101
     * @var string|null
102
     */
103
    protected ?string $rowActionRowIdPath = null;
104
105
    /**
106
     * @var string|null
107
     */
108
    protected ?string $availableRowActionsPath = null;
109
110
    /**
111
     * @var array<\Generated\Shared\Transfer\GuiTableBatchActionTransfer>
112
     */
113
    protected array $batchActions = [];
114
115
    /**
116
     * @var string|null
117
     */
118
    protected ?string $batchActionRowIdPath = null;
119
120
    /**
121
     * @var string|null
122
     */
123
    protected ?string $availableBatchActionsPath = null;
124
125
    /**
126
     * @var string|null
127
     */
128
    protected ?string $noBatchActionsMessage = null;
129
130
    /**
131
     * @var string|null
132
     */
133
    protected ?string $dataSourceUrl = null;
134
135
    /**
136
     * @var array<array<string>>
137
     */
138
    protected array $dataSourceInlineData = [];
139
140
    /**
141
     * @var int|null
142
     */
143
    protected ?int $defaultPageSize = null;
144
145
    /**
146
     * @var bool
147
     */
148
    protected bool $isSearchEnabled = true;
149
150
    /**
151
     * @var bool
152
     */
153
    protected bool $isColumnConfiguratorEnabled = true;
154
155
    /**
156
     * @var string|null
157
     */
158
    protected ?string $searchPlaceholder = null;
159
160
    /**
161
     * @var bool|null
162
     */
163
    protected ?bool $isItemSelectionEnabled = null;
164
165
    /**
166
     * @var \Generated\Shared\Transfer\GuiTableEditableConfigurationTransfer|null
167
     */
168
    protected ?GuiTableEditableConfigurationTransfer $editableConfiguration = null;
169
170
    /**
171
     * @var bool|null
172
     */
173
    protected ?bool $isPaginationEnabled = null;
174
175
    /**
176
     * @var bool
177
     */
178
    protected bool $isTotalEnabled = true;
179
180
    /**
181
     * @api
182
     *
183
     * @return \Generated\Shared\Transfer\GuiTableEditableConfigurationTransfer|null
184
     */
185
    public function getEditableConfiguration(): ?GuiTableEditableConfigurationTransfer
186
    {
187
        return $this->editableConfiguration;
188
    }
189
190
    /**
191
     * @api
192
     *
193
     * @return array<string, \Generated\Shared\Transfer\GuiTableColumnConfigurationTransfer>
194
     */
195
    public function getColumns(): array
196
    {
197
        return $this->columns;
198
    }
199
200
    /**
201
     * @api
202
     *
203
     * @param array<string, \Generated\Shared\Transfer\GuiTableColumnConfigurationTransfer> $columns
204
     *
205
     * @return $this
206
     */
207
    public function setColumns(array $columns)
208
    {
209
        $this->columns = $columns;
210
211
        return $this;
212
    }
213
214
    /**
215
     * @api
216
     *
217
     * @param string $id
218
     * @param string $title
219
     * @param bool $isSortable
220
     * @param bool $isHideable
221
     *
222
     * @return $this
223
     */
224
    public function addColumnText(
225
        string $id,
226
        string $title,
227
        bool $isSortable,
228
        bool $isHideable
229
    ) {
230
        $guiTableColumnConfigurationTransfer = (new GuiTableColumnConfigurationTransfer())
231
            ->setId($id)
232
            ->setTitle($title)
233
            ->setType(static::COLUMN_TYPE_TEXT)
234
            ->setSortable($isSortable)
235
            ->setHideable($isHideable);
236
237
        $this->addColumn($guiTableColumnConfigurationTransfer);
238
239
        return $this;
240
    }
241
242
    /**
243
     * @api
244
     *
245
     * @param string $id
246
     * @param string $title
247
     * @param bool $isSortable
248
     * @param bool $isHideable
249
     * @param string|null $idAltSourceColumn
250
     *
251
     * @return $this
252
     */
253
    public function addColumnImage(
254
        string $id,
255
        string $title,
256
        bool $isSortable,
257
        bool $isHideable,
258
        ?string $idAltSourceColumn = null
259
    ) {
260
        $guiTableColumnConfigurationTransfer = (new GuiTableColumnConfigurationTransfer())
261
            ->setId($id)
262
            ->setTitle($title)
263
            ->setType(static::COLUMN_TYPE_IMAGE)
264
            ->setSortable($isSortable)
265
            ->setHideable($isHideable);
266
267
        if ($idAltSourceColumn !== null) {
268
            $guiTableColumnConfigurationTransfer->addTypeOption('alt', sprintf('${row.%s}', $idAltSourceColumn));
269
        }
270
271
        $this->addColumn($guiTableColumnConfigurationTransfer);
272
273
        return $this;
274
    }
275
276
    /**
277
     * @api
278
     *
279
     * @param string $id
280
     * @param string $title
281
     * @param bool $isSortable
282
     * @param bool $isHideable
283
     * @param string|null $uiDateFormat
284
     *
285
     * @return $this
286
     */
287
    public function addColumnDate(
288
        string $id,
289
        string $title,
290
        bool $isSortable,
291
        bool $isHideable,
292
        ?string $uiDateFormat = null
293
    ) {
294
        $guiTableColumnConfigurationTransfer = (new GuiTableColumnConfigurationTransfer())
295
            ->setId($id)
296
            ->setTitle($title)
297
            ->setType(static::COLUMN_TYPE_DATE)
298
            ->setSortable($isSortable)
299
            ->setHideable($isHideable)
300
            ->addTypeOption('format', $uiDateFormat ?? static::DEFAULT_UI_DATE_FORMAT);
301
302
        $this->addColumn($guiTableColumnConfigurationTransfer);
303
304
        return $this;
305
    }
306
307
    /**
308
     * @api
309
     *
310
     * @param string $id
311
     * @param string $title
312
     * @param bool $isSortable
313
     * @param bool $isHideable
314
     * @param string|null $color
315
     * @param array<mixed>|null $colorMapping
316
     *
317
     * @return $this
318
     */
319
    public function addColumnChip(
320
        string $id,
321
        string $title,
322
        bool $isSortable,
323
        bool $isHideable,
324
        ?string $color,
325
        ?array $colorMapping = []
326
    ) {
327
        $guiTableColumnConfigurationTransfer = (new GuiTableColumnConfigurationTransfer())
328
            ->setId($id)
329
            ->setTitle($title)
330
            ->setType(static::COLUMN_TYPE_CHIP)
331
            ->setSortable($isSortable)
332
            ->setHideable($isHideable)
333
            ->addTypeOption('color', $color)
334
            ->addTypeOption('maxWidth', static::DEFAULT_CHIP_MAX_WIDTH)
335
            ->addTypeOptionMapping('color', $colorMapping);
336
337
        $this->addColumn($guiTableColumnConfigurationTransfer);
338
339
        return $this;
340
    }
341
342
    /**
343
     * @api
344
     *
345
     * @param string $id
346
     * @param string $title
347
     * @param bool $isSortable
348
     * @param bool $isHideable
349
     * @param int|null $limit
350
     * @param string|null $color
351
     *
352
     * @return $this
353
     */
354
    public function addColumnListChip(
355
        string $id,
356
        string $title,
357
        bool $isSortable,
358
        bool $isHideable,
359
        ?int $limit,
360
        ?string $color
361
    ) {
362
        $guiTableColumnConfigurationTransfer = (new GuiTableColumnConfigurationTransfer())
363
            ->setId($id)
364
            ->setTitle($title)
365
            ->setType(static::COLUMN_TYPE_LIST)
366
            ->setSortable($isSortable)
367
            ->setHideable($isHideable)
368
            ->addTypeOption('type', static::COLUMN_TYPE_CHIP)
369
            ->addTypeOption('limit', $limit);
370
371
        if ($color) {
372
            $guiTableColumnConfigurationTransfer->addTypeOption('typeOptions', [
373
                'color' => $color,
374
            ]);
375
        }
376
377
        $this->addColumn($guiTableColumnConfigurationTransfer);
378
379
        return $this;
380
    }
381
382
    /**
383
     * {@inheritDoc}
384
     *
385
     * @api
386
     *
387
     * @param string $id
388
     * @param string $title
389
     * @param bool $isSortable
390
     * @param bool $isHideable
391
     * @param string $text
392
     * @param string $actionUrl
393
     * @param string|null $modalTitle
394
     * @param string|null $modalDescription
395
     *
396
     * @return $this
397
     */
398
    public function addColumnButtonAction(
399
        string $id,
400
        string $title,
401
        bool $isSortable,
402
        bool $isHideable,
403
        string $text,
404
        string $actionUrl,
405
        ?string $modalTitle = null,
406
        ?string $modalDescription = null
407
    ) {
408
        $guiTableColumnConfigurationTransfer = (new GuiTableColumnConfigurationTransfer())
409
            ->setId($id)
410
            ->setTitle($title)
411
            ->setType(static::COLUMN_TYPE_BUTTON_ACTION)
412
            ->setSortable($isSortable)
413
            ->setHideable($isHideable)
414
            ->addTypeOption('text', $text)
415
            ->addTypeOption('variant', static::DEFAULT_COLUMN_BUTTON_ACTION_VARIANT)
416
            ->addTypeOption('size', static::DEFAULT_COLUMN_BUTTON_ACTION_SIZE);
417
418
        if ($modalTitle !== null && $modalDescription !== null) {
419
            $guiTableColumnConfigurationTransfer->addTypeOption(
420
                'action',
421
                $this->getTypeOptionConfirmationRedirect($actionUrl, $modalTitle, $modalDescription),
422
            );
423
            $this->addColumn($guiTableColumnConfigurationTransfer);
424
425
            return $this;
426
        }
427
428
        $guiTableColumnConfigurationTransfer->addTypeOption('action', $this->getTypeOptionRedirect($actionUrl));
429
        $this->addColumn($guiTableColumnConfigurationTransfer);
430
431
        return $this;
432
    }
433
434
    /**
435
     * @param \Generated\Shared\Transfer\GuiTableColumnConfigurationTransfer $guiTableColumnConfigurationTransfer
436
     *
437
     * @throws \Spryker\Shared\GuiTable\Exception\InvalidConfigurationException
438
     *
439
     * @return void
440
     */
441
    protected function addColumn(GuiTableColumnConfigurationTransfer $guiTableColumnConfigurationTransfer): void
442
    {
443
        $columnId = $guiTableColumnConfigurationTransfer->getIdOrFail();
444
445
        if (isset($this->columns[$columnId])) {
446
            throw new InvalidConfigurationException(sprintf('Column with id "%s" already exists', $columnId));
447
        }
448
449
        $this->columns[$columnId] = $guiTableColumnConfigurationTransfer;
450
    }
451
452
    /**
453
     * @api
454
     *
455
     * @param string $id
456
     * @param string $title
457
     * @param bool $isMultiselect
458
     * @param array<int|string, string> $values select values in format of ['value1' => 'title1', 'value2' => 'title2']
459
     *
460
     * @return $this
461
     */
462
    public function addFilterSelect(
463
        string $id,
464
        string $title,
465
        bool $isMultiselect,
466
        array $values
467
    ) {
468
        $typeOptionTransfers = (new SelectGuiTableFilterTypeOptionsTransfer())->setMultiselect($isMultiselect);
469
470
        foreach ($values as $value => $optionTitle) {
471
            $optionTransfer = (new OptionSelectGuiTableFilterTypeOptionsTransfer())
472
                ->setValue((string)$value)
473
                ->setTitle($optionTitle);
474
            $typeOptionTransfers->addValue($optionTransfer);
475
        }
476
477
        $this->filters[] = (new GuiTableFilterTransfer())
478
            ->setId($id)
479
            ->setTitle($title)
480
            ->setType(static::FILTER_TYPE_SELECT)
481
            ->setTypeOptions($typeOptionTransfers);
482
483
        return $this;
484
    }
485
486
    /**
487
     * @api
488
     *
489
     * @param string $id
490
     * @param string $title
491
     * @param bool $isMultiselect
492
     * @param array<\Generated\Shared\Transfer\OptionSelectGuiTableFilterTypeOptionsTransfer> $options
493
     *
494
     * @return $this
495
     */
496
    public function addFilterTreeSelect(string $id, string $title, bool $isMultiselect, array $options)
497
    {
498
        $typeOptionTransfers = (new SelectGuiTableFilterTypeOptionsTransfer())->setMultiselect($isMultiselect);
499
500
        foreach ($options as $optionTransfer) {
501
            $typeOptionTransfers->addValue($optionTransfer);
502
        }
503
504
        $this->filters[] = (new GuiTableFilterTransfer())
505
            ->setId($id)
506
            ->setTitle($title)
507
            ->setType(static::FILTER_TYPE_TREE_SELECT)
508
            ->setTypeOptions($typeOptionTransfers);
509
510
        return $this;
511
    }
512
513
    /**
514
     * @api
515
     *
516
     * @param string $id
517
     * @param string $title
518
     * @param string|null $placeholderFrom
519
     * @param string|null $placeholderTo
520
     *
521
     * @return $this
522
     */
523
    public function addFilterDateRange(
524
        string $id,
525
        string $title,
526
        ?string $placeholderFrom = null,
527
        ?string $placeholderTo = null
528
    ) {
529
        $guiTableFilterTransfer = (new GuiTableFilterTransfer())
530
            ->setId($id)
531
            ->setTitle($title)
532
            ->setType(static::FILTER_TYPE_DATE_RANGE);
533
534
        if ($placeholderFrom || $placeholderTo) {
535
            $guiTableFilterTransfer->setTypeOptions(
536
                (new DateRangeGuiTableFilterTypeOptionsTransfer())
537
                    ->setPlaceholderFrom($placeholderFrom)
538
                    ->setPlaceholderTo($placeholderTo),
539
            );
540
        }
541
542
        $this->filters[] = $guiTableFilterTransfer;
543
544
        return $this;
545
    }
546
547
    /**
548
     * @api
549
     *
550
     * @param string $id
551
     * @param string $title
552
     * @param string $url
553
     * @param string|null $method
554
     *
555
     * @return $this
556
     */
557
    public function addRowActionDrawerAjaxForm(
558
        string $id,
559
        string $title,
560
        string $url,
561
        ?string $method = null
562
    ) {
563
        $this->addRowAction(
564
            $id,
565
            $title,
566
            static::ACTION_TYPE_DRAWER,
567
            static::ACTION_DRAWER_COMPONENT_TYPE_AJAX_FORM,
568
            [
569
                'action' => $url,
570
                'method' => $method,
571
            ],
572
        );
573
574
        return $this;
575
    }
576
577
    /**
578
     * @api
579
     *
580
     * @param string $id
581
     * @param string $title
582
     * @param string $url
583
     * @param string|null $method
584
     *
585
     * @return $this
586
     */
587
    public function addRowActionDrawerUrlHtmlRenderer(
588
        string $id,
589
        string $title,
590
        string $url,
591
        ?string $method = null
592
    ) {
593
        $this->addRowAction(
594
            $id,
595
            $title,
596
            static::ACTION_TYPE_DRAWER,
597
            static::ACTION_DRAWER_COMPONENT_TYPE_URL_HTML_RENDERER,
598
            [
599
                'url' => $url,
600
                'method' => $method,
601
            ],
602
        );
603
604
        return $this;
605
    }
606
607
    /**
608
     * @api
609
     *
610
     * @param string $id
611
     * @param string $title
612
     * @param string $url
613
     * @param string|null $method
614
     *
615
     * @return $this
616
     */
617
    public function addRowActionHttp(
618
        string $id,
619
        string $title,
620
        string $url,
621
        ?string $method = null
622
    ) {
623
        $this->addRowAction(
624
            $id,
625
            $title,
626
            static::ACTION_TYPE_HTTP,
627
            null,
628
            [
629
                'url' => $url,
630
                'method' => $method,
631
            ],
632
        );
633
634
        return $this;
635
    }
636
637
    /**
638
     * @param string $id
639
     * @param string $title
640
     * @param string $type
641
     * @param string|null $component
642
     * @param array<string, mixed> $options
643
     *
644
     * @throws \Spryker\Shared\GuiTable\Exception\InvalidConfigurationException
645
     *
646
     * @return void
647
     */
648
    protected function addRowAction(
649
        string $id,
650
        string $title,
651
        string $type,
652
        ?string $component = null,
653
        array $options = []
654
    ): void {
655
        if (isset($this->rowActions[$id])) {
656
            throw new InvalidConfigurationException(sprintf('Row action with id "%s" already exists', $id));
657
        }
658
659
        $guiTableRowActionTransfer = (new GuiTableRowActionTransfer())
660
            ->setId($id)
661
            ->setTitle($title)
662
            ->setType($type);
663
664
        $this->rowActions[$id] = $guiTableRowActionTransfer;
665
666
        if ($type === static::ACTION_TYPE_HTTP) {
667
            $guiTableRowActionTransfer
668
                ->setUrl($options['url'])
669
                ->setMethod($options['method']);
670
671
            return;
672
        }
673
674
        $guiTableRowActionTransfer
675
            ->setComponent($component)
676
            ->setOptions(
677
                (new GuiTableRowActionOptionsTransfer())
678
                    ->setInputs($options),
679
            );
680
    }
681
682
    /**
683
     * @api
684
     *
685
     * @param string $id
686
     * @param string $title
687
     * @param string $url
688
     * @param string|null $method
689
     *
690
     * @return $this
691
     */
692
    public function addBatchActionDrawerAjaxForm(
693
        string $id,
694
        string $title,
695
        string $url,
696
        ?string $method = null
697
    ) {
698
        $this->addBatchAction(
699
            $id,
700
            $title,
701
            static::ACTION_TYPE_DRAWER,
702
            static::ACTION_DRAWER_COMPONENT_TYPE_AJAX_FORM,
703
            [
704
                'action' => $url,
705
                'method' => $method,
706
            ],
707
        );
708
709
        return $this;
710
    }
711
712
    /**
713
     * @api
714
     *
715
     * @param string $id
716
     * @param string $title
717
     * @param string $url
718
     * @param string|null $method
719
     *
720
     * @return $this
721
     */
722
    public function addBatchActionHttp(
723
        string $id,
724
        string $title,
725
        string $url,
726
        ?string $method = null
727
    ) {
728
        $this->addBatchAction(
729
            $id,
730
            $title,
731
            static::ACTION_TYPE_HTTP,
732
            null,
733
            [
734
                'url' => $url,
735
                'method' => $method,
736
            ],
737
        );
738
739
        return $this;
740
    }
741
742
    /**
743
     * @api
744
     *
745
     * @param string $id
746
     * @param string $title
747
     * @param string $url
748
     * @param string|null $method
749
     *
750
     * @throws \Spryker\Shared\GuiTable\Exception\InvalidConfigurationException
751
     *
752
     * @return $this
753
     */
754
    public function addBatchActionDrawerUrlHtmlRenderer(
755
        string $id,
756
        string $title,
757
        string $url,
758
        ?string $method = null
759
    ) {
760
        $this->addBatchAction(
761
            $id,
762
            $title,
763
            static::ACTION_TYPE_DRAWER,
764
            static::ACTION_DRAWER_COMPONENT_TYPE_URL_HTML_RENDERER,
765
            [
766
                'url' => $url,
767
                'method' => $method,
768
            ],
769
        );
770
771
        return $this;
772
    }
773
774
    /**
775
     * @param string $id
776
     * @param string $title
777
     * @param string $type
778
     * @param string|null $component
779
     * @param array<string, mixed> $options
780
     *
781
     * @throws \Spryker\Shared\GuiTable\Exception\InvalidConfigurationException
782
     *
783
     * @return void
784
     */
785
    protected function addBatchAction(
786
        string $id,
787
        string $title,
788
        string $type,
789
        ?string $component = null,
790
        array $options = []
791
    ): void {
792
        if (isset($this->batchActions[$id])) {
793
            throw new InvalidConfigurationException(sprintf('Batch action with id "%s" already exists', $id));
794
        }
795
796
        $guiTableBatchActionTransfer = (new GuiTableBatchActionTransfer())
797
            ->setId($id)
798
            ->setTitle($title)
799
            ->setType($type);
800
801
        $this->batchActions[$id] = $guiTableBatchActionTransfer;
802
803
        if ($type === static::ACTION_TYPE_HTTP) {
804
            $guiTableBatchActionTransfer
805
                ->setUrl($options['url'])
806
                ->setMethod($options['method']);
807
808
            return;
809
        }
810
811
        $guiTableBatchActionTransfer
812
            ->setComponent($component)
813
            ->setOptions(
814
                (new GuiTableBatchActionOptionsTransfer())
815
                    ->setInputs($options),
816
            );
817
    }
818
819
    /**
820
     * @api
821
     *
822
     * @return array<\Generated\Shared\Transfer\GuiTableRowActionTransfer>
823
     */
824
    public function getRowActions(): array
825
    {
826
        return $this->rowActions;
827
    }
828
829
    /**
830
     * @api
831
     *
832
     * @param string $id
833
     *
834
     * @throws \Spryker\Shared\GuiTable\Exception\RowActionNotFoundException
835
     *
836
     * @return \Generated\Shared\Transfer\GuiTableRowActionTransfer
837
     */
838
    public function getRowAction(string $id): GuiTableRowActionTransfer
839
    {
840
        if (!isset($this->rowActions[$id])) {
841
            throw new RowActionNotFoundException($id);
842
        }
843
844
        return $this->rowActions[$id];
845
    }
846
847
    /**
848
     * @api
849
     *
850
     * @param string $idAction
851
     *
852
     * @return $this
853
     */
854
    public function setRowClickAction(string $idAction)
855
    {
856
        $this->rowOnClickIdAction = $idAction;
857
858
        return $this;
859
    }
860
861
    /**
862
     * @api
863
     *
864
     * @param string $idPath
865
     *
866
     * @return $this
867
     */
868
    public function setRowActionRowIdPath(string $idPath)
869
    {
870
        $this->rowActionRowIdPath = $idPath;
871
872
        return $this;
873
    }
874
875
    /**
876
     * @api
877
     *
878
     * @param string $idPath
879
     *
880
     * @return $this
881
     */
882
    public function setBatchActionRowIdPath(string $idPath)
883
    {
884
        $this->batchActionRowIdPath = $idPath;
885
886
        return $this;
887
    }
888
889
    /**
890
     * @api
891
     *
892
     * @param string $availableRowActionsPath
893
     *
894
     * @return $this
895
     */
896
    public function setAvailableRowActionsPath(string $availableRowActionsPath)
897
    {
898
        $this->availableRowActionsPath = $availableRowActionsPath;
899
900
        return $this;
901
    }
902
903
    /**
904
     * @api
905
     *
906
     * @param string $availableBatchActionsPath
907
     *
908
     * @return $this
909
     */
910
    public function setAvailableBatchActionsPath(string $availableBatchActionsPath)
911
    {
912
        $this->availableBatchActionsPath = $availableBatchActionsPath;
913
914
        return $this;
915
    }
916
917
    /**
918
     * @api
919
     *
920
     * @param string $noBatchActionsMessage
921
     *
922
     * @return $this
923
     */
924
    public function setNoBatchActionsMessage(string $noBatchActionsMessage)
925
    {
926
        $this->noBatchActionsMessage = $noBatchActionsMessage;
927
928
        return $this;
929
    }
930
931
    /**
932
     * @api
933
     *
934
     * @param string $url
935
     *
936
     * @return $this
937
     */
938
    public function setDataSourceUrl(string $url)
939
    {
940
        $this->dataSourceUrl = $url;
941
942
        return $this;
943
    }
944
945
    /**
946
     * @api
947
     *
948
     * @param array<array<string>> $data
949
     *
950
     * @return $this
951
     */
952
    public function setDataSourceInlineData(array $data)
953
    {
954
        $this->dataSourceInlineData = $data;
955
956
        return $this;
957
    }
958
959
    /**
960
     * @api
961
     *
962
     * @param int $defaultPageSize
963
     *
964
     * @return $this
965
     */
966
    public function setDefaultPageSize(int $defaultPageSize)
967
    {
968
        $this->defaultPageSize = $defaultPageSize;
969
970
        return $this;
971
    }
972
973
    /**
974
     * @api
975
     *
976
     * @param bool $isEnabled
977
     *
978
     * @return $this
979
     */
980
    public function isSearchEnabled(bool $isEnabled = true)
981
    {
982
        $this->isSearchEnabled = false;
983
984
        return $this;
985
    }
986
987
    /**
988
     * @api
989
     *
990
     * @param bool $isEnabled
991
     *
992
     * @return $this
993
     */
994
    public function isColumnConfiguratorEnabled(bool $isEnabled = true)
995
    {
996
        $this->isColumnConfiguratorEnabled = false;
997
998
        return $this;
999
    }
1000
1001
    /**
1002
     * @api
1003
     *
1004
     * @param string $searchPlaceholder
1005
     *
1006
     * @return $this
1007
     */
1008
    public function setSearchPlaceholder(string $searchPlaceholder)
1009
    {
1010
        $this->searchPlaceholder = $searchPlaceholder;
1011
1012
        return $this;
1013
    }
1014
1015
    /**
1016
     * @api
1017
     *
1018
     * @param bool $isItemSelectionEnabled
1019
     *
1020
     * @return $this
1021
     */
1022
    public function setIsItemSelectionEnabled(bool $isItemSelectionEnabled)
1023
    {
1024
        $this->isItemSelectionEnabled = $isItemSelectionEnabled;
1025
1026
        return $this;
1027
    }
1028
1029
    /**
1030
     * @api
1031
     *
1032
     * @param string $title
1033
     *
1034
     * @return $this
1035
     */
1036
    public function setTableTitle(string $title)
1037
    {
1038
        $this->title = $title;
1039
1040
        return $this;
1041
    }
1042
1043
    /**
1044
     * @api
1045
     *
1046
     * @param bool $isPaginationEnabled
1047
     *
1048
     * @return $this
1049
     */
1050
    public function setIsPaginationEnabled(bool $isPaginationEnabled)
1051
    {
1052
        $this->isPaginationEnabled = $isPaginationEnabled;
1053
1054
        return $this;
1055
    }
1056
1057
    /**
1058
     * {@inheritDoc}
1059
     *
1060
     * @api
1061
     *
1062
     * @param bool $isTotalEnabled
1063
     *
1064
     * @return $this
1065
     */
1066
    public function setIsTotalEnabled(bool $isTotalEnabled)
1067
    {
1068
        $this->isTotalEnabled = $isTotalEnabled;
1069
1070
        return $this;
1071
    }
1072
1073
    /**
1074
     * @api
1075
     *
1076
     * @throws \Spryker\Shared\GuiTable\Exception\InvalidConfigurationException
1077
     *
1078
     * @return \Generated\Shared\Transfer\GuiTableConfigurationTransfer
1079
     */
1080
    public function createConfiguration(): GuiTableConfigurationTransfer
1081
    {
1082
        if (!$this->columns) {
1083
            throw new InvalidConfigurationException('Table must have at least one column');
1084
        }
1085
1086
        $guiTableConfigurationTransfer = new GuiTableConfigurationTransfer();
1087
1088
        $guiTableConfigurationTransfer->setColumns(new ArrayObject($this->columns));
1089
        $guiTableConfigurationTransfer = $this->setFilters($guiTableConfigurationTransfer);
1090
        $guiTableConfigurationTransfer = $this->setRowActions($guiTableConfigurationTransfer);
1091
        $guiTableConfigurationTransfer = $this->setBatchActions($guiTableConfigurationTransfer);
1092
        $guiTableConfigurationTransfer = $this->setDataSource($guiTableConfigurationTransfer);
1093
1094
        if ($this->title) {
1095
            $guiTableConfigurationTransfer->setTitle(
1096
                (new GuiTableTitleConfigurationTransfer())
1097
                    ->setIsEnabled(true)
1098
                    ->setTitle($this->title),
1099
            );
1100
        }
1101
1102
        if ($this->defaultPageSize) {
1103
            $guiTableConfigurationTransfer->setPagination(
1104
                (new GuiTablePaginationConfigurationTransfer())->setDefaultSize($this->defaultPageSize),
1105
            );
1106
        }
1107
1108
        $guiTableConfigurationTransfer->setColumnConfigurator(
1109
            (new GuiTableColumnConfiguratorConfigurationTransfer())->setEnabled($this->isColumnConfiguratorEnabled),
1110
        );
1111
1112
        $guiTableConfigurationTransfer->setSearch(
1113
            (new GuiTableSearchConfigurationTransfer())->setIsEnabled($this->isSearchEnabled),
1114
        );
1115
1116
        $guiTableConfigurationTransfer->setTotal(
1117
            (new GuiTableTotalConfigurationTransfer())->setIsEnabled($this->isTotalEnabled),
1118
        );
1119
1120
        if ($this->searchPlaceholder) {
1121
            $guiTableConfigurationTransfer->getSearchOrFail()
1122
                ->addSearchOption('placeholder', $this->searchPlaceholder);
1123
        }
1124
1125
        if ($this->isItemSelectionEnabled !== null) {
1126
            $guiTableConfigurationTransfer->setItemSelection(
1127
                (new GuiTableItemSelectionConfigurationTransfer())->setIsEnabled($this->isItemSelectionEnabled),
1128
            );
1129
        }
1130
1131
        if ($this->editableConfiguration) {
1132
            $guiTableConfigurationTransfer->setEditable($this->editableConfiguration);
1133
        }
1134
1135
        if ($this->isPaginationEnabled !== null) {
1136
            $guiTableConfigurationTransfer->setPagination(
1137
                (new GuiTablePaginationConfigurationTransfer())->setIsEnabled($this->isPaginationEnabled),
1138
            );
1139
        }
1140
1141
        return $guiTableConfigurationTransfer;
1142
    }
1143
1144
    /**
1145
     * @api
1146
     *
1147
     * @param string $formInputName
1148
     * @param array<string, mixed> $initialData
1149
     * @param array<string, mixed>|null $addButton
1150
     * @param array<string, mixed>|null $cancelButton
1151
     *
1152
     * @return $this
1153
     */
1154
    public function enableAddingNewRows(
1155
        string $formInputName,
1156
        array $initialData = [],
1157
        ?array $addButton = null,
1158
        ?array $cancelButton = null
1159
    ) {
1160
        if (!$this->editableConfiguration) {
1161
            $this->editableConfiguration = (new GuiTableEditableConfigurationTransfer())->setEnabled(true);
1162
        }
1163
1164
        $guiTableEditableInitialDataTransfer = (bool)$initialData ? $this->mapInitialDataToTransfer($initialData) : null;
1165
        $guiTableEditableCreateConfigurationTransfer = (new GuiTableEditableCreateConfigurationTransfer())
1166
            ->setFormInputName($formInputName)
1167
            ->setInitialData($guiTableEditableInitialDataTransfer)
1168
            ->setCancelButton($this->createEditableCancelButton($cancelButton))
1169
            ->setAddButton($this->createEditableAddButton($addButton));
1170
1171
        $this->editableConfiguration->setCreate($guiTableEditableCreateConfigurationTransfer);
1172
1173
        return $this;
1174
    }
1175
1176
    /**
1177
     * @api
1178
     *
1179
     * @param string $url
1180
     * @param string $method
1181
     * @param array<string, mixed>|null $saveButton
1182
     * @param array<string, mixed>|null $cancelButton
1183
     *
1184
     * @return $this
1185
     */
1186
    public function enableInlineDataEditing(
1187
        string $url,
1188
        string $method = 'POST',
1189
        ?array $saveButton = null,
1190
        ?array $cancelButton = null
1191
    ) {
1192
        if (!$this->editableConfiguration) {
1193
            $this->editableConfiguration = (new GuiTableEditableConfigurationTransfer())->setEnabled(true);
1194
        }
1195
1196
        $guiTableEditableUpdateConfigurationTransfer = (new GuiTableEditableUpdateConfigurationTransfer())
1197
            ->setUrl($this->createEditableUrl($url, $method))
1198
            ->setSaveButton($this->createEditableSaveButton($saveButton))
1199
            ->setCancelButton($this->createEditableCancelButton($cancelButton));
1200
1201
        $this->editableConfiguration->setUpdate($guiTableEditableUpdateConfigurationTransfer);
1202
1203
        return $this;
1204
    }
1205
1206
    /**
1207
     * @api
1208
     *
1209
     * @param string $id
1210
     * @param string $title
1211
     * @param string $inputType
1212
     * @param array<string, mixed> $options
1213
     *
1214
     * @return $this
1215
     */
1216
    public function addEditableColumnInput(string $id, string $title, string $inputType = 'text', array $options = [])
1217
    {
1218
        $guiTableColumnConfigurationTransfer = (new GuiTableColumnConfigurationTransfer())
1219
            ->setId($id)
1220
            ->setTitle($title)
1221
            ->setType(static::COLUMN_TYPE_INPUT);
1222
1223
        $options = array_merge([
1224
            'type' => $inputType,
1225
        ], $options);
1226
1227
        $guiTableColumnConfigurationTransfer->setTypeOptions($options);
1228
1229
        $this->addEditableColumn($guiTableColumnConfigurationTransfer);
1230
1231
        return $this;
1232
    }
1233
1234
    /**
1235
     * @api
1236
     *
1237
     * @param string $id
1238
     * @param string $title
1239
     * @param bool $isMultiselect
1240
     * @param array<int|string, mixed> $options
1241
     * @param string|null $placeholder
1242
     *
1243
     * @return $this
1244
     */
1245
    public function addEditableColumnSelect(
1246
        string $id,
1247
        string $title,
1248
        bool $isMultiselect,
1249
        array $options,
1250
        ?string $placeholder = null
1251
    ) {
1252
        $guiTableColumnConfigurationTransfer = (new GuiTableColumnConfigurationTransfer())
1253
            ->setId($id)
1254
            ->setTitle($title)
1255
            ->setType(static::COLUMN_TYPE_SELECT);
1256
1257
        $typeOptionValues = [];
1258
1259
        foreach ($options as $value => $optionTitle) {
1260
            $typeOptionValues['options'][] = [
1261
                'title' => $optionTitle,
1262
                'value' => $value,
1263
            ];
1264
        }
1265
1266
        if ($placeholder) {
1267
            $typeOptionValues['placeholder'] = $placeholder;
1268
        }
1269
1270
        $guiTableColumnConfigurationTransfer->setTypeOptions($typeOptionValues);
1271
1272
        $this->addEditableColumn($guiTableColumnConfigurationTransfer);
1273
1274
        return $this;
1275
    }
1276
1277
    /**
1278
     * @api
1279
     *
1280
     * @param string $id
1281
     * @param string $title
1282
     * @param string $dependableColumn
1283
     * @param array<string|int, mixed> $dataSetTypeOptions
1284
     * @param array<string|int, mixed>|null $defaultTypeOptions
1285
     *
1286
     * @return $this
1287
     */
1288
    public function addInlineEditableColumnDynamic(
1289
        string $id,
1290
        string $title,
1291
        string $dependableColumn,
1292
        array $dataSetTypeOptions,
1293
        ?array $defaultTypeOptions = null
1294
    ) {
1295
        $guiTableColumnConfigurationTransfer = (new GuiTableColumnConfigurationTransfer())
1296
            ->setId($id)
1297
            ->setTitle($title)
1298
            ->setType(static::COLUMN_TYPE_DYNAMIC)
1299
            ->setTypeOptions([
1300
                'datasource' => [
1301
                    'type' => static::DATA_SOURCE_TYPE_DEPENDABLE,
1302
                    'dependsOn' => $dependableColumn,
1303
                    'datasource' => [
1304
                        'type' => static::DATA_SOURCE_TYPE_INLINE,
1305
                        'data' => $dataSetTypeOptions,
1306
                        'dependsOnContext' => [
1307
                            'contextKey' => $dependableColumn,
1308
                            'default' => $defaultTypeOptions,
1309
                        ],
1310
                    ],
1311
                ],
1312
            ]);
1313
1314
        $this->addEditableColumn($guiTableColumnConfigurationTransfer);
1315
1316
        return $this;
1317
    }
1318
1319
    /**
1320
     * @param array<string, mixed> $initialData
1321
     *
1322
     * @return \Generated\Shared\Transfer\GuiTableEditableInitialDataTransfer
1323
     */
1324
    protected function mapInitialDataToTransfer(array $initialData): GuiTableEditableInitialDataTransfer
1325
    {
1326
        $guiTableEditableInitialDataTransfer = (new GuiTableEditableInitialDataTransfer())
1327
            ->fromArray($initialData, true);
1328
        $errors = $initialData[GuiTableEditableInitialDataTransfer::ERRORS] ?? null;
1329
1330
        if (!$errors) {
1331
            return $guiTableEditableInitialDataTransfer;
1332
        }
1333
1334
        $guiTableEditableDataErrorTransfers = [];
1335
1336
        foreach ($errors as $error) {
1337
            $rowError = $error[GuiTableEditableDataErrorTransfer::ROW_ERROR] ?? null;
1338
            $columnErrors = $error[GuiTableEditableDataErrorTransfer::COLUMN_ERRORS] ?? [];
1339
1340
            $guiTableEditableDataErrorTransfers[] = (new GuiTableEditableDataErrorTransfer())
1341
                ->setRowError($rowError)
1342
                ->setColumnErrors($columnErrors);
1343
        }
1344
1345
        return $guiTableEditableInitialDataTransfer->setErrors(new ArrayObject($guiTableEditableDataErrorTransfers));
1346
    }
1347
1348
    /**
1349
     * @param string $url
1350
     * @param string $method
1351
     *
1352
     * @return \Generated\Shared\Transfer\GuiTableEditableUrlTransfer
1353
     */
1354
    protected function createEditableUrl(string $url, string $method): GuiTableEditableUrlTransfer
1355
    {
1356
        return (new GuiTableEditableUrlTransfer())
1357
            ->setMethod($method)
1358
            ->setUrl($url);
1359
    }
1360
1361
    /**
1362
     * @param array<string, mixed>|null $addButton
1363
     *
1364
     * @return \Generated\Shared\Transfer\GuiTableEditableButtonTransfer
1365
     */
1366
    protected function createEditableAddButton(?array $addButton): GuiTableEditableButtonTransfer
1367
    {
1368
        $editableButtonOptions = $this->resolveEditableButtonOptions($addButton, [
1369
            GuiTableEditableButtonTransfer::TITLE => 'Create',
1370
        ]);
1371
1372
        return $this->createEditableButton($editableButtonOptions);
1373
    }
1374
1375
    /**
1376
     * @param array<string, mixed>|null $saveButton
1377
     *
1378
     * @return \Generated\Shared\Transfer\GuiTableEditableButtonTransfer
1379
     */
1380
    protected function createEditableSaveButton(?array $saveButton): GuiTableEditableButtonTransfer
1381
    {
1382
        $editableButtonOptions = $this->resolveEditableButtonOptions($saveButton, [
1383
            GuiTableEditableButtonTransfer::TITLE => 'Save',
1384
        ]);
1385
1386
        return $this->createEditableButton($editableButtonOptions);
1387
    }
1388
1389
    /**
1390
     * @param array<string, mixed>|null $cancelButton
1391
     *
1392
     * @return \Generated\Shared\Transfer\GuiTableEditableButtonTransfer
1393
     */
1394
    protected function createEditableCancelButton(?array $cancelButton): GuiTableEditableButtonTransfer
1395
    {
1396
        $editableButtonOptions = $this->resolveEditableButtonOptions($cancelButton, [
1397
            GuiTableEditableButtonTransfer::TITLE => 'Cancel',
1398
        ]);
1399
1400
        return $this->createEditableButton($editableButtonOptions);
1401
    }
1402
1403
    /**
1404
     * @param array<string, mixed>|null $editableButtonOptions
1405
     * @param array<string, mixed> $defaultOverwriteOptions
1406
     *
1407
     * @return array<string, ?string>
1408
     */
1409
    protected function resolveEditableButtonOptions(?array $editableButtonOptions, array $defaultOverwriteOptions): array
1410
    {
1411
        $editableButtonOptions = $editableButtonOptions ?? [];
1412
1413
        $defaultOptions = [
1414
            GuiTableEditableButtonTransfer::TITLE => null,
1415
            GuiTableEditableButtonTransfer::ICON => null,
1416
            GuiTableEditableButtonTransfer::VARIANT => null,
1417
            GuiTableEditableButtonTransfer::SIZE => null,
1418
            GuiTableEditableButtonTransfer::SHAPE => null,
1419
        ];
1420
1421
        return array_merge($defaultOptions, $defaultOverwriteOptions, $editableButtonOptions);
1422
    }
1423
1424
    /**
1425
     * @param array<string, ?string> $editableButtonOptions
1426
     *
1427
     * @return \Generated\Shared\Transfer\GuiTableEditableButtonTransfer
1428
     */
1429
    protected function createEditableButton(
1430
        array $editableButtonOptions
1431
    ): GuiTableEditableButtonTransfer {
1432
        return (new GuiTableEditableButtonTransfer())
1433
            ->setTitle($editableButtonOptions[GuiTableEditableButtonTransfer::TITLE])
1434
            ->setIcon($editableButtonOptions[GuiTableEditableButtonTransfer::ICON])
1435
            ->setVariant($editableButtonOptions[GuiTableEditableButtonTransfer::VARIANT])
1436
            ->setSize($editableButtonOptions[GuiTableEditableButtonTransfer::SIZE])
1437
            ->setShape($editableButtonOptions[GuiTableEditableButtonTransfer::SHAPE]);
1438
    }
1439
1440
    /**
1441
     * @param \Generated\Shared\Transfer\GuiTableColumnConfigurationTransfer $guiTableColumnConfigurationTransfer
1442
     *
1443
     * @throws \Spryker\Shared\GuiTable\Exception\InvalidConfigurationException
1444
     *
1445
     * @return void
1446
     */
1447
    protected function addEditableColumn(GuiTableColumnConfigurationTransfer $guiTableColumnConfigurationTransfer): void
1448
    {
1449
        $columnId = $guiTableColumnConfigurationTransfer->getIdOrFail();
1450
1451
        if (isset($this->editableColumns[$columnId])) {
1452
            throw new InvalidConfigurationException(sprintf('Editable column with id "%s" already exists', $columnId));
1453
        }
1454
1455
        if (!$this->editableConfiguration) {
1456
            $this->editableConfiguration = (new GuiTableEditableConfigurationTransfer())->setEnabled(true);
1457
        }
1458
1459
        $this->editableConfiguration->addColumn($guiTableColumnConfigurationTransfer);
1460
    }
1461
1462
    /**
1463
     * @param \Generated\Shared\Transfer\GuiTableConfigurationTransfer $guiTableConfigurationTransfer
1464
     *
1465
     * @return \Generated\Shared\Transfer\GuiTableConfigurationTransfer
1466
     */
1467
    protected function setFilters(GuiTableConfigurationTransfer $guiTableConfigurationTransfer): GuiTableConfigurationTransfer
1468
    {
1469
        $guiTableConfigurationTransfer->setFilters(
1470
            (new GuiTableFiltersConfigurationTransfer())->setIsEnabled(false),
1471
        );
1472
1473
        if ($this->filters) {
1474
            $guiTableConfigurationTransfer->getFiltersOrFail()
1475
                ->setIsEnabled(true)
1476
                ->setItems(new ArrayObject($this->filters));
1477
        }
1478
1479
        return $guiTableConfigurationTransfer;
1480
    }
1481
1482
    /**
1483
     * @param \Generated\Shared\Transfer\GuiTableConfigurationTransfer $guiTableConfigurationTransfer
1484
     *
1485
     * @return \Generated\Shared\Transfer\GuiTableConfigurationTransfer
1486
     */
1487
    protected function setRowActions(GuiTableConfigurationTransfer $guiTableConfigurationTransfer): GuiTableConfigurationTransfer
1488
    {
1489
        $guiTableConfigurationTransfer->setRowActions(
1490
            (new GuiTableRowActionsConfigurationTransfer())->setIsEnabled(false),
1491
        );
1492
1493
        if ($this->rowActions) {
1494
            $guiTableConfigurationTransfer->getRowActionsOrFail()
1495
                ->setIsEnabled(true)
1496
                ->setActions(new ArrayObject($this->rowActions))
1497
                ->setClick($this->rowOnClickIdAction)
1498
                ->setRowIdPath($this->rowActionRowIdPath)
1499
                ->setAvailableActionsPath($this->availableRowActionsPath);
1500
        }
1501
1502
        return $guiTableConfigurationTransfer;
1503
    }
1504
1505
    /**
1506
     * @param \Generated\Shared\Transfer\GuiTableConfigurationTransfer $guiTableConfigurationTransfer
1507
     *
1508
     * @return \Generated\Shared\Transfer\GuiTableConfigurationTransfer
1509
     */
1510
    protected function setBatchActions(GuiTableConfigurationTransfer $guiTableConfigurationTransfer): GuiTableConfigurationTransfer
1511
    {
1512
        $guiTableBatchActionsConfigurationTransfer = (new GuiTableBatchActionsConfigurationTransfer())
1513
            ->setIsEnabled(false);
1514
1515
        if ($this->batchActions) {
1516
            $guiTableBatchActionsConfigurationTransfer
1517
                ->setIsEnabled(true)
1518
                ->setActions(new ArrayObject($this->batchActions))
1519
                ->setRowIdPath($this->batchActionRowIdPath)
1520
                ->setAvailableActionsPath($this->availableBatchActionsPath)
1521
                ->setNoActionsMessage($this->noBatchActionsMessage);
1522
        }
1523
1524
        $guiTableConfigurationTransfer->setBatchActions($guiTableBatchActionsConfigurationTransfer);
1525
1526
        return $guiTableConfigurationTransfer;
1527
    }
1528
1529
    /**
1530
     * @param \Generated\Shared\Transfer\GuiTableConfigurationTransfer $guiTableConfigurationTransfer
1531
     *
1532
     * @return \Generated\Shared\Transfer\GuiTableConfigurationTransfer
1533
     */
1534
    protected function setDataSource(GuiTableConfigurationTransfer $guiTableConfigurationTransfer): GuiTableConfigurationTransfer
1535
    {
1536
        $guiTableDataSourceConfigurationTransfer = new GuiTableDataSourceConfigurationTransfer();
1537
1538
        if ($this->dataSourceUrl) {
1539
            $guiTableDataSourceConfigurationTransfer->setUrl($this->dataSourceUrl);
1540
        }
1541
1542
        if ($this->dataSourceInlineData) {
1543
            $guiTableDataSourceConfigurationTransfer->setData($this->dataSourceInlineData)
1544
                ->setType(GuiTableConfigurationBuilderInterface::DATA_SOURCE_TYPE_INLINE);
1545
        }
1546
1547
        $guiTableConfigurationTransfer->setDataSource($guiTableDataSourceConfigurationTransfer);
1548
1549
        return $guiTableConfigurationTransfer;
1550
    }
1551
1552
    /**
1553
     * @api
1554
     *
1555
     * @param string $id
1556
     * @param string $title
1557
     * @param string $dependableColumn
1558
     * @param string $dependableUrl
1559
     *
1560
     * @throws \Spryker\Shared\GuiTable\Exception\InvalidConfigurationException
1561
     *
1562
     * @return $this
1563
     */
1564
    public function addEditableColumnDynamic(string $id, string $title, string $dependableColumn, string $dependableUrl)
1565
    {
1566
        $guiTableColumnConfigurationTransfer = (new GuiTableColumnConfigurationTransfer())
1567
            ->setId($id)
1568
            ->setTitle($title)
1569
            ->setType(static::COLUMN_TYPE_DYNAMIC)
1570
            ->setTypeOptions([
1571
                'datasource' => [
1572
                    'type' => static::DATA_SOURCE_TYPE_DEPENDABLE,
1573
                    'dependsOn' => $dependableColumn,
1574
                    'datasource' => [
1575
                        'type' => static::DATA_SOURCE_TYPE_HTTP,
1576
                        'url' => $dependableUrl,
1577
                    ],
1578
                ],
1579
            ]);
1580
1581
        $this->addEditableColumn($guiTableColumnConfigurationTransfer);
1582
1583
        return $this;
1584
    }
1585
1586
    /**
1587
     * @api
1588
     *
1589
     * @param string $columnId
1590
     * @param string $displayKey
1591
     *
1592
     * @return $this
1593
     */
1594
    public function setColumnDisplayKey(string $columnId, string $displayKey)
1595
    {
1596
        $guiTableColumnConfigurationTransfer = $this->columns[$columnId];
1597
        $guiTableColumnConfigurationTransfer->setDisplayKey($displayKey);
1598
        $this->columns[$columnId] = $guiTableColumnConfigurationTransfer;
1599
1600
        return $this;
1601
    }
1602
1603
    /**
1604
     * @param string $actionUrl
1605
     * @param string $modalTitle
1606
     * @param string $modalDescription
1607
     *
1608
     * @return array<string, mixed>
1609
     */
1610
    protected function getTypeOptionConfirmationRedirect(
1611
        string $actionUrl,
1612
        string $modalTitle,
1613
        string $modalDescription
1614
    ): array {
1615
        return [
1616
            'type' => 'confirmation',
1617
            'action' => [
1618
                'type' => 'redirect',
1619
                'url' => $actionUrl,
1620
            ],
1621
            'modal' => [
1622
                'title' => $modalTitle,
1623
                'description' => $modalDescription,
1624
                'okVariant' => static::DEFAULT_MODAL_OK_BUTTON_VARIANT,
1625
            ],
1626
        ];
1627
    }
1628
1629
    /**
1630
     * @param string $actionUrl
1631
     *
1632
     * @return array<string, string>
1633
     */
1634
    protected function getTypeOptionRedirect(string $actionUrl): array
1635
    {
1636
        return [
1637
            'type' => 'redirect',
1638
            'url' => $actionUrl,
1639
        ];
1640
    }
1641
}
1642