File tree Expand file tree Collapse file tree 3 files changed +42
-14
lines changed
Expand file tree Collapse file tree 3 files changed +42
-14
lines changed Original file line number Diff line number Diff line change 1010use Redberry \PageBuilderPlugin \Components \Forms \PageBuilder ;
1111use Redberry \PageBuilderPlugin \Components \Forms \RadioButtonImage ;
1212use Redberry \PageBuilderPlugin \Traits \CanRenderWithThumbnails ;
13+ use Redberry \PageBuilderPlugin \Traits \FormatsBlockCategories ;
1314
1415class SelectBlockAction extends Action
1516{
1617 use CanRenderWithThumbnails;
18+ use FormatsBlockCategories;
1719
1820 public ?Closure $ modifySelectionFieldUsing = null ;
1921
@@ -86,7 +88,7 @@ protected function setUp(): void
8688 });
8789 }
8890
89- private function formatBlocksForSelect (PageBuilder $ component ): array
91+ private function formatBlocksForRadio (PageBuilder $ component ): array
9092 {
9193 $ blocks = $ component ->getBlocks ();
9294
@@ -100,4 +102,19 @@ private function formatBlocksForSelect(PageBuilder $component): array
100102
101103 return $ formatted ;
102104 }
105+
106+ private function formatBlocksForSelect (PageBuilder $ component ): array
107+ {
108+ $ blocks = $ component ->getBlocks ();
109+
110+ $ formatted = [];
111+
112+ foreach ($ blocks as $ block ) {
113+ $ category = $ this ->getCategoryTitle ($ block ::getCategory ());
114+
115+ $ formatted [$ category ][$ block ] = $ block ::getBlockName ();
116+ }
117+
118+ return $ formatted ;
119+ }
103120}
Original file line number Diff line number Diff line change 1111use Illuminate \Contracts \Support \Htmlable ;
1212use Illuminate \View \ComponentAttributeBag ;
1313use Redberry \PageBuilderPlugin \Abstracts \BaseBlock ;
14- use Redberry \PageBuilderPlugin \Abstracts \ BaseBlockCategory ;
14+ use Redberry \PageBuilderPlugin \Traits \ FormatsBlockCategories ;
1515
1616class RadioButtonImage extends Field
1717{
1818 use CanDisableOptions;
1919 use HasExtraInputAttributes;
2020 use HasGridDirection;
2121 use HasOptions;
22+ use FormatsBlockCategories;
2223
2324 public string $ view = 'page-builder-plugin::forms.radio-button-image ' ;
2425
@@ -50,18 +51,6 @@ public function getAllTabAttributes(): ComponentAttributeBag
5051 return $ this ->evaluate ($ this ->allTabAttributes ) ?? new ComponentAttributeBag ();
5152 }
5253
53- public function isCategoryClass (string $ category ): bool
54- {
55- return class_exists ($ category ) && is_subclass_of ($ category , BaseBlockCategory::class);
56- }
57-
58- public function getCategoryTitle (string $ category ): string
59- {
60- return class_exists ($ category ) && method_exists ($ category , 'getCategoryName ' )
61- ? (string ) $ this ->evaluate (Closure::fromCallable ([$ category , 'getCategoryName ' ]))
62- : $ category ;
63- }
64-
6554 public function getFormattedOptions (): array
6655 {
6756 $ options = $ this ->getOptions ();
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Redberry \PageBuilderPlugin \Traits ;
4+
5+ use Closure ;
6+ use Redberry \PageBuilderPlugin \Abstracts \BaseBlockCategory ;
7+
8+ trait FormatsBlockCategories
9+ {
10+ public function isCategoryClass (string $ category ): bool
11+ {
12+ return class_exists ($ category ) && is_subclass_of ($ category , BaseBlockCategory::class);
13+ }
14+
15+ public function getCategoryTitle (string $ category ): string
16+ {
17+ return class_exists ($ category ) && method_exists ($ category , 'getCategoryName ' )
18+ ? (string ) $ this ->evaluate (Closure::fromCallable ([$ category , 'getCategoryName ' ]))
19+ : $ category ;
20+ }
21+
22+ }
You can’t perform that action at this time.
0 commit comments