PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.5.5
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.5.5
1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 All 49 releases
fluent-cart / app / Hooks / Handlers / BlockEditors / MediaCarousel / MediaCarouselBlockEditor.php

MediaCarouselBlockEditor.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.5.5, at app/Hooks/Handlers/BlockEditors/MediaCarousel/MediaCarouselBlockEditor.php

132 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Hooks\Handlers\BlockEditors\MediaCarousel;
4
5 use FluentCart\App\Helpers\Helper;
6 use FluentCart\App\Hooks\Handlers\BlockEditors\BlockEditor;
7 use FluentCart\App\Hooks\Handlers\BlockEditors\MediaCarousel\InnerBlocks\InnerBlocks;
8 use FluentCart\App\Hooks\Handlers\ShortCodes\ShopAppHandler;
9 use FluentCart\App\Modules\Templating\AssetLoader;
10 use FluentCart\App\Services\Translations\TransStrings;
11 use FluentCart\App\Vite;
12 use FluentCart\Framework\Support\Arr;
13
14 class MediaCarouselBlockEditor extends BlockEditor
15 {
16 protected static string $editorName = 'media-carousel';
17
18 protected ?string $localizationKey = 'fluent_cart_media_carousel_block_editor_data';
19
20 public function getScripts(): array
21 {
22 return [
23 [
24 'source' => 'admin/BlockEditor/MediaCarousel/MediaCarouselBlockEditor.jsx',
25 'dependencies' => [
26 'wp-blocks',
27 'wp-components',
28 'wp-block-editor',
29 'wp-data',
30 'wp-element',
31 ]
32 ]
33 ];
34 }
35
36 public function getStyles(): array
37 {
38 return [
39 'admin/BlockEditor/ShopApp/style/shop-app-block-editor.css',
40 'admin/BlockEditor/ProductInfo/style/product-info-block-editor.scss',
41 'admin/BlockEditor/MediaCarousel/style/media-carousel-block-editor.scss'
42 ];
43 }
44
45 public function init(): void
46 {
47 parent::init();
48
49 $this->registerInnerBlocks();
50 }
51
52 public function registerInnerBlocks()
53 {
54 InnerBlocks::register();
55 }
56
57 public function localizeData(): array
58 {
59 return [
60 $this->getLocalizationKey() => [
61 'rest' => Helper::getRestInfo(),
62 'slug' => $this->slugPrefix,
63 'name' => static::getEditorName(),
64 'trans' => TransStrings::getShopAppBlockEditorString(),
65 'title' => __('Media Carousel', 'fluent-cart'),
66 'description' => __('This block will display the media carousel.', 'fluent-cart'),
67 'placeholder_image' => Vite::getAssetUrl('images/placeholder.svg')
68 ],
69 'fluent_cart_block_editor_asset' => [
70 'placeholder_image' => Vite::getAssetUrl('images/placeholder.svg'),
71 ],
72 'fluent_cart_block_translation' => TransStrings::blockStrings(),
73 'fluentCartCarouselVars' => [
74 'defaultSlides' => 3,
75 'spaceBetween' => 16,
76 'breakpoints' => [
77 0 => ['slidesPerView' => 1],
78 768 => ['slidesPerView' => 2],
79 1024 => ['slidesPerView' => 3],
80 1280 => ['slidesPerView' => 4],
81 ],
82 'rtl' => is_rtl(),
83 ],
84 ];
85 }
86
87 public function provideContext(): array
88 {
89 // in which name the data will be received => which attr
90 return [
91 'fluent-cart/query_type' => 'query_type',
92 'fluent-cart/carousel_settings' => 'carousel_settings',
93 'fluent-cart/product_id' => 'product_id',
94 'fluent-cart/variation_ids' => 'variation_ids',
95 'fluent-cart/has_controls' => 'has_controls',
96 'fluent-cart/has_pagination' => 'has_pagination',
97 ];
98 }
99
100 public function render(array $shortCodeAttribute, $block = null, $content = null): string
101 {
102 AssetLoader::loadProductArchiveAssets();
103
104 $app = fluentCart();
105 $slug = $app->config->get('app.slug');
106
107 Vite::enqueueStaticScript(
108 $slug . '-fluentcart-swiper-js',
109 'public/lib/swiper/swiper-bundle.min.js',
110 [$slug . '-app',]
111 );
112
113 Vite::enqueueStaticStyle(
114 $slug . '-fluentcart-swiper-css',
115 'public/lib/swiper/swiper-bundle.min.css',
116 );
117
118 Vite::enqueueStyle(
119 'fluentcart-media-carousel',
120 'public/carousel/media/style/media-carousel.scss',
121 );
122
123 Vite::enqueueScript(
124 'fluentcart-media-carousel',
125 'public/carousel/media/media-carousel.js',
126 []
127 );
128
129 return $content;
130 }
131 }
132