Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/fluentform/app/Services/Blocks/GutenbergBlock.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
3
+
namespace FluentForm\App\Services\Blocks;
4
+
5
+
use FluentForm\App\Helpers\Helper;
6
+
use FluentForm\Framework\Support\Arr;
7
+
8
+
/**
9
+
* GutenbergBlock class for handling Fluent Forms Gutenberg block functionality
10
+
* @since 1.0.0
11
+
*/
12
+
class GutenbergBlock
13
+
{
14
+
/**
15
+
* Register the Gutenberg block
16
+
* @return void
17
+
*/
18
+
public static function register()
19
+
{
20
+
if (!function_exists('register_block_type')) {
21
+
return;
22
+
}
23
+
24
+
register_block_type('fluentfom/guten-block', [
25
+
'render_callback' => [self::class, 'render'],
26
+
'attributes' => BlockAttributes::getAttributes(),
27
+
'api_version' => 3,
28
+
]);
29
+
}
30
+
31
+
/**
32
+
* Render the Gutenberg block
33
+
*
34
+
* @param array $atts Block attributes
35
+
* @return string Rendered block HTML
36
+
*/
37
+
public static function render($atts)
38
+
{
39
+
$formId = (int)Arr::get($atts, 'formId', 0);
40
+
41
+
if (!$formId) {
42
+
return '<div class="fluentform-no-form-selected"><p>' . __('Please select a form', 'fluentform') . '</p></div>';
43
+
}
44
+
45
+
$className = sanitize_text_field(Arr::get($atts, 'className', ''));
46
+
$themeStyle = sanitize_text_field(Arr::get($atts, 'themeStyle', ''));
47
+
$type = Helper::isConversionForm($formId) ? 'conversational' : '';
48
+
49
+
// Custom CSS for block styling
50
+
51
+
$inlineStyle = '';
52
+
$customCss = Arr::get($atts, 'customCss', '');
53
+
54
+
$customCss = json_decode($customCss, true);
55
+
$customCss = is_string($customCss) ? $customCss : '';
56
+
57
+
if ($customCss && $customCss = fluentformSanitizeCSS($customCss)) {
58
+
$styleId = 'fluentform-block-custom-styles-' . $formId;
59
+
$inlineStyle = '<style id="' . esc_attr($styleId) . '">' . $customCss . '</style>';
60
+
if (wp_style_is('fluent-form-styles', 'enqueued') || wp_style_is('fluent-form-styles', 'registered')) {
61
+
wp_add_inline_style('fluent-form-styles', $customCss);
62
+
}
63
+
if (wp_style_is('fluentform-public-default', 'enqueued') || wp_style_is('fluentform-public-default', 'registered')) {
64
+
wp_add_inline_style('fluentform-public-default', $customCss);
65
+
}
66
+
}
67
+
68
+
// Return the form with inline styles
69
+
$formOutput = do_shortcode('[fluentform theme="' . $themeStyle . '" css_classes="' . $className . ' ff_guten_block ff_guten_block-' . $formId . '" id="' . $formId . '" type="' . $type . '"]');
70
+
71
+
if ($formOutput) {
72
+
$allStyles = '';
73
+
if ($inlineStyle) {
74
+
$allStyles .= $inlineStyle;
75
+
}
76
+
// if (!empty($individualStyleTag)) {
77
+
// $allStyles .= $individualStyleTag;
78
+
// }
79
+
80
+
if ($allStyles) {
81
+
return $allStyles . $formOutput;
82
+
}
83
+
return $formOutput;
84
+
}
85
+
86
+
return '';
87
+
}
88
+
}
89
+