PluginProbe
Hello Plus / 1.5.2
Hello Plus v1.5.2
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.6.0 1.6.1 1.6.2 1.7.0 1.7.1 1.7.2 1.7.3 All 30 releases
hello-plus / modules / forms / classes / render / widget-form-render.php

widget-form-render.php in Hello Plus 1.5.2, at modules/forms/classes/render/widget-form-render.php

351 lines 11.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace HelloPlus\Modules\Forms\Classes\Render;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 use HelloPlus\Modules\Forms\Widgets\Ehp_Form;
9 use HelloPlus\Includes\Utils;
10 use Elementor\Icons_Manager;
11
12 use HelloPlus\Classes\{
13 Ehp_Full_Height,
14 Ehp_Image,
15 Ehp_Shapes,
16 Widget_Utils,
17 };
18
19 class Widget_Form_Render {
20 protected Ehp_Form $widget;
21 protected array $settings;
22
23 const LAYOUT_CLASSNAME = 'ehp-form';
24
25 public function render() {
26 $layout_full_height_controls = $this->settings['box_full_screen_height_controls'] ?? '';
27 $layout_preset = $this->settings['layout_preset'] ?? '';
28
29 $layout_classnames = [
30 self::LAYOUT_CLASSNAME,
31 'has-layout-preset-' . $this->settings['layout_preset'],
32 ];
33
34 if ( ! empty( $layout_full_height_controls ) ) {
35 foreach ( $layout_full_height_controls as $breakpoint ) {
36 $layout_classnames[] = ' is-full-height-' . $breakpoint;
37 }
38 }
39
40 if ( 'yes' === $this->settings['show_box_border'] ) {
41 $layout_classnames[] = 'has-border';
42 }
43
44 if ( ! empty( $this->settings['layout_column_structure'] ) ) {
45 $layout_classnames[] = 'has-column-structure-' . $this->settings['layout_column_structure'];
46 }
47
48 if ( 'yes' === $this->settings['layout_reverse_structure'] ) {
49 $layout_classnames[] = 'is-reverse';
50 }
51
52 if ( 'yes' === $this->settings['image_stretch'] ) {
53 $layout_classnames[] = 'has-image-stretch';
54 }
55
56 $shapes = new Ehp_Shapes( $this->widget, [
57 'container_prefix' => 'box',
58 'render_attribute' => 'layout',
59 'widget_name' => 'form',
60 ] );
61 $shapes->add_shape_attributes();
62
63 $ehp_full_height = new Ehp_Full_Height( $this->widget );
64 $ehp_full_height->add_full_height_attributes();
65
66 $this->widget->add_render_attribute( 'layout', [
67 'name' => $this->settings['form_name'] || '',
68 'class' => $layout_classnames,
69 'method' => 'post',
70 ] );
71
72 $this->widget->add_render_attribute( 'wrapper', [
73 'class' => self::LAYOUT_CLASSNAME . '__wrapper',
74 ] );
75
76 $referer_title = trim( wp_title( '', false ) );
77
78 if ( ! $referer_title && is_home() ) {
79 $referer_title = get_option( 'blogname' );
80 }
81
82 $this->widget->add_render_attribute( 'overlay', [
83 'class' => self::LAYOUT_CLASSNAME . '__overlay',
84 ] );
85
86 $this->widget->add_render_attribute( 'content', 'class', self::LAYOUT_CLASSNAME . '__content' );
87
88 ?>
89 <form <?php $this->widget->print_render_attribute_string( 'layout' ); ?>>
90 <?php if ( 'engage' !== $layout_preset ) {
91 $this->render_text_container();
92 } else {
93 $this->render_image_container();
94 } ?>
95 <input type="hidden" name="post_id" value="<?php echo (int) Utils::get_current_post_id(); ?>"/>
96 <input type="hidden" name="form_id" value="<?php echo esc_attr( $this->widget->get_id() ); ?>"/>
97 <input type="hidden" name="referer_title" value="<?php echo esc_attr( $referer_title ); ?>"/>
98
99 <?php if ( is_singular() ) {
100 // `queried_id` may be different from `post_id` on Single theme builder templates.
101 ?>
102 <input type="hidden" name="queried_id" value="<?php echo (int) get_the_ID(); ?>"/>
103 <?php } ?>
104
105 <div <?php $this->widget->print_render_attribute_string( 'content' ); ?>>
106 <?php if ( 'engage' === $layout_preset ) {
107 $this->render_text_container();
108 } ?>
109 <div <?php $this->widget->print_render_attribute_string( 'wrapper' ); ?>>
110 <?php
111 foreach ( $this->settings['form_fields'] as $item_index => $item ) :
112 $item['input_size'] = $this->settings['input_size'];
113 $this->widget->form_fields_render_attributes( $item_index, $this->settings, $item );
114
115 $field_type = $item['field_type'];
116
117 /**
118 * Render form field.
119 *
120 * Filters the field rendered by Elementor forms.
121 *
122 * @param array $item The field value.
123 * @param int $item_index The field index.
124 * @param Ehp_Form $this An instance of the form.
125 *
126 * @since 1.0.0
127 *
128 */
129 $item = apply_filters( 'hello_plus/forms/render/item', $item, $item_index, $this );
130
131 /**
132 * Render form field.
133 *
134 * Filters the field rendered by Elementor forms.
135 *
136 * The dynamic portion of the hook name, `$field_type`, refers to the field type.
137 *
138 * @param array $item The field value.
139 * @param int $item_index The field index.
140 * @param Ehp_Form $this An instance of the form.
141 *
142 * @since 1.0.0
143 *
144 */
145 $item = apply_filters( "hello_plus/forms/render/item/{$field_type}", $item, $item_index, $this );
146
147 $print_label = ! in_array( $item['field_type'], [ 'hidden', 'html', 'step' ], true );
148 ?>
149 <div <?php $this->widget->print_render_attribute_string( 'field-group' . $item_index ); ?>>
150 <?php
151 if ( $print_label && $item['field_label'] ) {
152 ?>
153 <label <?php $this->widget->print_render_attribute_string( 'label' . $item_index ); ?>>
154 <?php
155 echo esc_html( $item['field_label'] ); ?>
156 </label>
157 <?php
158 }
159
160 switch ( $item['field_type'] ) :
161 case 'textarea':
162 echo wp_kses(
163 $this->widget->make_textarea_field( $item, $item_index, $this->settings ),
164 [
165 'textarea' => [
166 'cols' => true,
167 'rows' => true,
168 'name' => true,
169 'id' => true,
170 'class' => true,
171 'style' => true,
172 'placeholder' => true,
173 'maxlength' => true,
174 'required' => true,
175 'readonly' => true,
176 'disabled' => true,
177 ],
178 ]
179 );
180 break;
181
182 case 'select':
183 echo wp_kses( $this->widget->make_select_field( $item, $item_index ), [
184 'select' => [
185 'name' => true,
186 'id' => true,
187 'class' => true,
188 'style' => true,
189 'required' => true,
190 'disabled' => true,
191 ],
192 'option' => [
193 'value' => true,
194 'selected' => true,
195 ],
196 ] );
197 break;
198
199 case 'text':
200 case 'email':
201 $this->widget->add_render_attribute( 'input' . $item_index, 'class', 'elementor-field-textual' );
202 ?>
203 <input size="1" <?php $this->widget->print_render_attribute_string( 'input' . $item_index ); ?>>
204 <?php
205 break;
206
207 default:
208 $field_type = $item['field_type'];
209
210 /**
211 * Hello+ form field render.
212 *
213 * Fires when a field is rendered in the frontend. This hook allows developers to
214 * add functionality when from fields are rendered.
215 *
216 * The dynamic portion of the hook name, `$field_type`, refers to the field type.
217 *
218 * @param array $item The field value.
219 * @param int $item_index The field index.
220 * @param Ehp_Form $this An instance of the form.
221 *
222 * @since 1.0.0
223 *
224 */
225 do_action( "hello_plus/forms/render_field/{$field_type}", $item, $item_index, $this->widget );
226 endswitch;
227 ?>
228 </div>
229 <?php endforeach; ?>
230 <?php $this->render_button(); ?>
231 </div>
232 </div>
233 <div <?php $this->widget->print_render_attribute_string( 'overlay' ); ?>></div>
234 </form>
235 <?php
236 }
237
238 protected function render_button(): void {
239 $button_classnames = [ self::LAYOUT_CLASSNAME . '__button' ];
240 $submit_group_classnames = [ self::LAYOUT_CLASSNAME . '__submit-group' ];
241
242 if ( ! empty( $this->settings['button_width'] ) ) {
243 $submit_group_classnames[] = 'has-width-' . $this->settings['button_width'];
244
245 if ( ! empty( $this->settings['button_width_tablet'] ) ) {
246 $submit_group_classnames[] = 'has-width-md-' . $this->settings['button_width_tablet'];
247 }
248
249 if ( ! empty( $this->settings['button_width_mobile'] ) ) {
250 $submit_group_classnames[] = 'has-width-sm-' . $this->settings['button_width_mobile'];
251 }
252 }
253
254 if ( ! empty( $this->settings['button_align'] ) ) {
255 $submit_group_classnames[] = 'has-button-align-' . $this->settings['button_align'];
256
257 if ( ! empty( $this->settings['button_align_tablet'] ) ) {
258 $submit_group_classnames[] = 'has-button-align-md-' . $this->settings['button_align_tablet'];
259 }
260
261 if ( ! empty( $this->settings['button_align_mobile'] ) ) {
262 $submit_group_classnames[] = 'has-button-align-sm-' . $this->settings['button_align_mobile'];
263 }
264 }
265
266 $this->widget->add_render_attribute( 'submit-group', [
267 'class' => $submit_group_classnames,
268 ] );
269
270 if ( 'yes' === $this->settings['button_border_switcher'] ) {
271 $button_classnames[] = 'has-border';
272 }
273
274 $shapes = new Ehp_Shapes( $this->widget, [
275 'container_prefix' => 'button',
276 'render_attribute' => 'button',
277 'widget_name' => 'form',
278 ] );
279 $shapes->add_shape_attributes();
280
281 if ( ! empty( $this->settings['button_type'] ) ) {
282 $button_classnames[] = 'is-type-' . $this->settings['button_type'];
283 }
284
285 if ( $this->settings['button_hover_animation'] ) {
286 $button_classnames[] = 'elementor-animation-' . $this->settings['button_hover_animation'];
287 }
288
289 $this->widget->add_render_attribute( 'button', [
290 'class' => $button_classnames,
291 'type' => 'submit',
292 ] );
293
294 if ( ! empty( $this->settings['button_css_id'] ) ) {
295 $this->widget->add_render_attribute( 'button', 'id', $this->settings['button_css_id'] );
296 }
297
298 $this->widget->add_render_attribute( 'button-text', [
299 'class' => self::LAYOUT_CLASSNAME . '__button-text',
300 ] );
301 ?>
302 <div <?php $this->widget->print_render_attribute_string( 'submit-group' ); ?>>
303 <button <?php $this->widget->print_render_attribute_string( 'button' ); ?>>
304 <?php if ( ! empty( $this->settings['selected_button_icon'] ) || ! empty( $this->settings['selected_button_icon']['value'] ) ) : ?>
305 <?php
306 Icons_Manager::render_icon( $this->settings['selected_button_icon'],
307 [
308 'aria-hidden' => 'true',
309 'class' => self::LAYOUT_CLASSNAME . '__button-icon',
310 ],
311 );
312 ?>
313 <?php endif; ?>
314
315 <?php if ( ! empty( $this->settings['button_text'] ) ) : ?>
316 <span <?php $this->widget->print_render_attribute_string( 'button-text' ); ?>><?php $this->widget->print_unescaped_setting( 'button_text' ); ?></span>
317 <?php endif; ?>
318 </button>
319 </div>
320 <?php
321 }
322
323 protected function render_text_container(): void {
324 $heading_classname = self::LAYOUT_CLASSNAME . '__heading';
325 $description_classname = self::LAYOUT_CLASSNAME . '__description';
326
327 $this->widget->add_render_attribute( 'text-container', [
328 'class' => self::LAYOUT_CLASSNAME . '__text-container',
329 ] );
330 ?>
331 <div <?php $this->widget->print_render_attribute_string( 'text-container' ); ?>>
332 <?php
333 Widget_Utils::maybe_render_text_html( $this->widget, 'text_heading', $heading_classname, $this->settings['text_heading'], $this->settings['text_heading_tag'] );
334 Widget_Utils::maybe_render_text_html( $this->widget, 'text_description', $description_classname, $this->settings['text_description'] );
335 ?>
336 </div>
337 <?php
338 }
339
340 protected function render_image_container() {
341 $image = new Ehp_Image( $this->widget, [
342 'widget_name' => 'form',
343 ] );
344 $image->render();
345 }
346 public function __construct( Ehp_Form $widget ) {
347 $this->widget = $widget;
348 $this->settings = $widget->get_settings_for_display();
349 }
350 }
351