PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.21.4
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.21.4
V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 2.10.2 All 137 releases
bit-form / includes / Widgets / BitformBricksWidget.php

BitformBricksWidget.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.21.4, at includes/Widgets/BitformBricksWidget.php

115 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Widgets;
4
5 use BitCode\BitForm\GlobalHelper;
6
7 if (!defined('ABSPATH')) {
8 exit;
9 }
10
11 /**
12 * BitformBricksWidget class.
13 *
14 * @package BitCode\BitForm\Widgets
15 *
16 * @since
17 *
18 * @version
19 *
20 * @description
21 * This class is used to create a Bitform widget for Bricks Builder.
22 * It extends the \Bricks\Element class and implements the necessary methods to register the widget.
23 *
24 * @see https://academy.bricksbuilder.io/article/create-your-own-elements/
25 */
26 class BitformBricksWidget extends \Bricks\Element
27 {
28 public $category = 'general';
29 public $name = 'Bit Form';
30 public $icon = 'ti-layout-cta-left';
31
32 public $tag = 'form';
33
34 public function get_label()
35 {
36 return esc_html__('Bit Form', 'bricks');
37 }
38
39 public function get_keywords()
40 {
41 return [
42 'bitform',
43 'bitforms',
44 'form',
45 'bitform widget',
46 'form widget',
47 'contact forms',
48 'bricks form',
49 'bit form',
50 'form builder',
51 'shortcode',
52 ];
53 }
54
55 // Set builder controls
56 public function set_controls()
57 {
58 $options = [];
59 if (is_callable([GlobalHelper::class, 'getForms'])) {
60 $forms = GlobalHelper::getForms();
61 if (is_array($forms)) {
62 $options = $forms;
63 }
64 }
65 $this->controls['form-list'] = [
66 'label' => esc_html__('Form list', 'bricks'),
67 'type' => 'select',
68 'options' => $options,
69 'inline' => true,
70 'clearable' => false,
71 ];
72 }
73
74 public function enqueue_scripts()
75 {
76 // for custom script
77 }
78
79 private function getStyle($formId)
80 {
81 $style = '';
82 if (file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')) {
83 $cssFile = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . "bitform-{$formId}-formid" . '.css';
84
85 if (file_exists($cssFile)) {
86 $style = file_get_contents($cssFile);
87 } else {
88 $style = '';
89 }
90 }
91 return "<style>$style</style>";
92 }
93
94 public function render()
95 {
96 echo "<div {$this->render_attributes('_root')}>";
97 if (empty($this->settings['form-list'])) {
98 echo $this->render_element_placeholder([ // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
99
100 'icon-class' => $this->icon,
101 'title' => esc_html__('No form selected', 'bit-form'),
102 'description' => esc_html__('Please select a form from the Form List available in the Bit Form element settings.', 'bit-form'),
103
104 // Legacy attribute
105 'text' => esc_html__('No form selected', 'bit-form')
106 ]);
107 }
108 if (!empty($this->settings['form-list'])) {
109 echo $this->getStyle($this->settings['form-list']);
110 echo do_shortcode('[bitform id="' . $this->settings['form-list'] . '"]');
111 }
112 echo '</div>';
113 }
114 }
115