PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.5.3
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.5.3
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 / ProductDescriptionBlockEditor.php

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

122 lines 3.8 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;
4
5 use FluentCart\App\Modules\Templating\AssetLoader;
6 use FluentCart\App\Services\Translations\TransStrings;
7 use FluentCart\App\Vite;
8 use FluentCart\Framework\Support\Arr;
9 use FluentCart\App\Models\Product;
10
11 class ProductDescriptionBlockEditor extends BlockEditor
12 {
13 protected static string $editorName = 'product-description';
14
15 public function ancestor(): array
16 {
17 return [
18 'fluent-cart/products',
19 'fluent-cart/product-carousel',
20 'fluent-cart/product-info',
21 'fluent-cart/related-product',
22 ];
23 }
24
25 public function supports(): array
26 {
27 return [
28 'html' => false,
29 'align' => true,
30 'typography' => [
31 'fontSize' => true,
32 'lineHeight' => true,
33 '__experimentalFontFamily' => true,
34 '__experimentalFontWeight' => true,
35 '__experimentalFontStyle' => true,
36 '__experimentalTextTransform' => true,
37 '__experimentalTextDecoration' => true,
38 '__experimentalLetterSpacing' => true,
39 '__experimentalDefaultControls' => [
40 'fontSize' => true,
41 'lineHeight' => true,
42 'fontWeight' => true,
43 ],
44 ],
45 'color' => [
46 'text' => true,
47 'background' => true,
48 'link' => true,
49 'gradients' => true,
50 ],
51 'spacing' => [
52 'margin' => true,
53 'padding' => true,
54 ],
55 '__experimentalBorder' => [
56 'color' => true,
57 'radius' => true,
58 'style' => true,
59 'width' => true,
60 ],
61 'shadow' => true,
62 ];
63 }
64
65 public function getScripts(): array
66 {
67 return [
68 [
69 'source' => 'admin/BlockEditor/ProductDescription/ProductDescriptionBlockEditor.jsx',
70 'dependencies' => ['wp-blocks', 'wp-components']
71 ]
72 ];
73 }
74
75 public function getStyles(): array
76 {
77 return [
78 'admin/BlockEditor/ProductDescription/style/product-description-block-editor.scss'
79 ];
80 }
81
82 public function localizeData(): array
83 {
84 return [
85 $this->getLocalizationKey() => [
86 'slug' => $this->slugPrefix,
87 'name' => static::getEditorName(),
88 'title' => __('Product Description', 'fluent-cart'),
89 'description' => __('This block will display the full product description.', 'fluent-cart'),
90 'placeholder_image' => Vite::getAssetUrl('images/placeholder.svg')
91 ],
92 'fluent_cart_block_translation' => TransStrings::blockStrings(),
93 ];
94 }
95
96 public function render(array $shortCodeAttribute, $block = null)
97 {
98 AssetLoader::loadSingleProductAssets();
99
100 $productId = absint(Arr::get($shortCodeAttribute, 'product_id', 0));
101
102 if ($productId) {
103 $product = Product::query()->find($productId);
104 } else {
105 $product = fluent_cart_get_current_product();
106 }
107
108 if (!$product || empty($product->post_content)) {
109 return '';
110 }
111
112 $wrapper_attributes = get_block_wrapper_attributes([
113 'class' => 'fct-product-description',
114 ]);
115
116 return sprintf(
117 '<div %s>%s</div>',
118 $wrapper_attributes,
119 wpautop(wp_kses_post($product->post_content))
120 );
121 }
122 }