PluginProbe
Hello Plus / 1.7.0
Hello Plus v1.7.0
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.7.0, at modules/forms/classes/render/widget-form-render.php

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