| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Hooks\Handlers\BlockEditors; |
| 4 |
|
| 5 |
use FluentCart\App\Hooks\Handlers\ShortCodes\SearchBarShortCode; |
| 6 |
use FluentCart\App\Services\Translations\TransStrings; |
| 7 |
use FluentCart\App\Vite; |
| 8 |
use FluentCart\Framework\Support\Arr; |
| 9 |
|
| 10 |
class SearchBarBlockEditor extends BlockEditor |
| 11 |
{ |
| 12 |
protected static string $editorName = 'fluent-products-search-bar'; |
| 13 |
|
| 14 |
public function getScripts(): array |
| 15 |
{ |
| 16 |
return [ |
| 17 |
[ |
| 18 |
'source' => 'admin/BlockEditor/SearchBar/SearchBarBlockEditor.jsx', |
| 19 |
'dependencies' => ['wp-blocks', 'wp-components'] |
| 20 |
] |
| 21 |
]; |
| 22 |
} |
| 23 |
|
| 24 |
public function getStyles(): array |
| 25 |
{ |
| 26 |
return ['admin/BlockEditor/SearchBar/style/searchbar-block-editor.css']; |
| 27 |
} |
| 28 |
|
| 29 |
public function localizeData(): array |
| 30 |
{ |
| 31 |
return [ |
| 32 |
$this->getLocalizationKey() => [ |
| 33 |
'slug' => $this->slugPrefix, |
| 34 |
'name' => static::getEditorName(), |
| 35 |
'title' => __('Product Search', 'fluent-cart'), |
| 36 |
], |
| 37 |
'fluent_cart_block_editor_asset' => [ |
| 38 |
'placeholder_image' => Vite::getAssetUrl('images/placeholder.svg'), |
| 39 |
], |
| 40 |
'fluent_cart_block_translation' => TransStrings::blockStrings() |
| 41 |
]; |
| 42 |
} |
| 43 |
|
| 44 |
public function render(array $shortCodeAttribute, $block = null): string |
| 45 |
{ |
| 46 |
$urlMode = Arr::get($shortCodeAttribute, 'url_mode'); |
| 47 |
$categoryMode = Arr::get($shortCodeAttribute, 'category_mode'); |
| 48 |
$linkWithShopApp = Arr::get($shortCodeAttribute, 'link_with_shop_app'); |
| 49 |
$showThumbnail = Arr::get($shortCodeAttribute, 'show_thumbnail', true); |
| 50 |
|
| 51 |
return SearchBarShortCode::make([ |
| 52 |
'url_mode' => !empty($urlMode) ? $urlMode : 'new-tab', |
| 53 |
'category_mode' => !empty($categoryMode) ? $categoryMode : '', |
| 54 |
'link_with_shop_app' => !empty($linkWithShopApp) ? $linkWithShopApp : '', |
| 55 |
'show_thumbnail' => $showThumbnail, |
| 56 |
])->renderShortcode($block); |
| 57 |
} |
| 58 |
|
| 59 |
} |
| 60 |
|