Skip to content

Commit 3844b58

Browse files
committed
fix: full class being visible for section
1 parent d78096e commit 3844b58

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

src/Components/Forms/Actions/SelectBlockAction.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
use Redberry\PageBuilderPlugin\Components\Forms\PageBuilder;
1111
use Redberry\PageBuilderPlugin\Components\Forms\RadioButtonImage;
1212
use Redberry\PageBuilderPlugin\Traits\CanRenderWithThumbnails;
13+
use Redberry\PageBuilderPlugin\Traits\FormatsBlockCategories;
1314

1415
class 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
}

src/Components/Forms/RadioButtonImage.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
use Illuminate\Contracts\Support\Htmlable;
1212
use Illuminate\View\ComponentAttributeBag;
1313
use Redberry\PageBuilderPlugin\Abstracts\BaseBlock;
14-
use Redberry\PageBuilderPlugin\Abstracts\BaseBlockCategory;
14+
use Redberry\PageBuilderPlugin\Traits\FormatsBlockCategories;
1515

1616
class 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();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
}

0 commit comments

Comments
 (0)