PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 0.0.13
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v0.0.13
2.12.7 2.12.6 2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 0.0.2 All 97 releases
sureforms / inc / fields / multichoice-markup.php

multichoice-markup.php in SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz 0.0.13, at inc/fields/multichoice-markup.php

180 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Sureforms Multichoice Markup Class file.
4 *
5 * @package sureforms.
6 * @since 0.0.1
7 */
8
9 namespace SRFM\Inc\Fields;
10
11 use Spec_Gb_Helper;
12 use SRFM\Inc\Helper;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit; // Exit if accessed directly.
16 }
17
18 /**
19 * SureForms Multichoice Markup Class.
20 *
21 * @since 0.0.1
22 */
23 class Multichoice_Markup extends Base {
24
25 /**
26 * Flag indicating if only a single selection is allowed.
27 *
28 * @var bool
29 * @since 0.0.2
30 */
31 protected $single_selection;
32
33 /**
34 * Width of the choice input field.
35 *
36 * @var string
37 * @since 0.0.2
38 */
39 protected $choice_width;
40
41 /**
42 * HTML attribute string for the choice width.
43 *
44 * @var string
45 * @since 0.0.2
46 */
47 protected $choice_width_attr;
48
49 /**
50 * HTML attribute string for the input type (radio or checkbox).
51 *
52 * @var string
53 * @since 0.0.2
54 */
55 protected $type_attr;
56
57 /**
58 * SVG type for the input field.
59 *
60 * @var string
61 * @since 0.0.7
62 */
63 protected $svg_type;
64
65 /**
66 * HTML attribute string for the name attribute of the input field.
67 *
68 * @var string
69 * @since 0.0.2
70 */
71 protected $name_attr;
72
73 /**
74 * Flag indicating if the layout is vertical.
75 *
76 * @var bool
77 * @since 0.0.7
78 */
79 protected $vertical_layout;
80
81 /**
82 * Contains value if the option contains icon / image
83 *
84 * @var mixed
85 * @since 0.0.7
86 */
87 protected $option_type;
88
89 /**
90 * Initialize the properties based on block attributes.
91 *
92 * @param array<mixed> $attributes Block attributes.
93 * @since 0.0.2
94 */
95 public function __construct( $attributes ) {
96 $this->set_properties( $attributes );
97 $this->set_input_label( __( 'Multi Choice', 'sureforms' ) );
98 $this->set_error_msg( $attributes, 'srfm_multi_choice_block_required_text' );
99 $this->slug = 'multi-choice';
100 $this->single_selection = isset( $attributes['singleSelection'] ) ? $attributes['singleSelection'] : false;
101 $this->choice_width = isset( $attributes['choiceWidth'] ) ? $attributes['choiceWidth'] : '';
102 $this->vertical_layout = isset( $attributes['verticalLayout'] ) ? $attributes['verticalLayout'] : false;
103 $this->option_type = ! empty( $attributes['optionType'] ) && in_array( $attributes['optionType'], [ 'icon', 'image' ], true ) ? $attributes['optionType'] : 'icon';
104 $this->type_attr = $this->single_selection ? 'radio' : 'checkbox';
105 $this->svg_type = $this->single_selection ? 'circle' : 'square';
106 $this->name_attr = $this->single_selection ? 'name="srfm-input-' . esc_attr( $this->slug ) . '-' . esc_attr( $this->block_id ) . '"' : '';
107 $this->choice_width_attr = $this->choice_width ? 'srfm-choice-width-' . str_replace( '.', '-', $this->choice_width ) : '';
108 $this->set_markup_properties();
109 }
110
111 /**
112 * Data attribute markup for min and max value
113 *
114 * @since 0.0.13
115 * @return string
116 */
117 protected function data_attribute_markup() {
118 $data_attr = '';
119 if ( $this->single_selection ) {
120 return '';
121 }
122
123 if ( $this->min_selection ) {
124 $data_attr .= 'data-min-selection="' . esc_attr( $this->min_selection ) . '"';
125 }
126 if ( $this->max_selection ) {
127 $data_attr .= 'data-max-selection="' . esc_attr( $this->max_selection ) . '"';
128 }
129
130 return $data_attr;
131 }
132
133 /**
134 * Render the sureforms Multichoice classic styling
135 *
136 * @since 0.0.2
137 * @return string|boolean
138 */
139 public function markup() {
140 $check_svg = Helper::fetch_svg( $this->svg_type . '-checked', 'srfm-' . $this->slug . '-icon' );
141 $unchecked_svg = Helper::fetch_svg( $this->svg_type . '-unchecked', 'srfm-' . $this->slug . '-icon-unchecked' );
142 ob_start(); ?>
143 <div data-block-id="<?php echo esc_attr( $this->block_id ); ?>" class="srfm-block-single srfm-block srfm-<?php echo esc_attr( $this->type_attr ); ?>-mode srfm-<?php echo esc_attr( $this->slug ); ?>-block srf-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?>-block<?php echo wp_kses_post( $this->block_width ); ?><?php echo esc_attr( $this->class_name ); ?> <?php echo esc_attr( $this->conditional_class ); ?>">
144 <fieldset>
145 <input class="srfm-input-<?php echo esc_attr( $this->slug ); ?>-hidden" aria-required="<?php echo esc_attr( $this->aria_require_attr ); ?>" <?php echo wp_kses_post( $this->data_attribute_markup() ); ?> name="srfm-input-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?><?php echo esc_attr( $this->field_name ); ?>" type="hidden" value=""/>
146 <legend><?php echo wp_kses_post( $this->label_markup ); ?></legend>
147 <?php echo wp_kses_post( $this->help_markup ); ?>
148 <?php if ( is_array( $this->options ) ) { ?>
149 <div class="srfm-block-wrap <?php echo esc_attr( $this->choice_width_attr ); ?> <?php echo( $this->vertical_layout ? 'srfm-vertical-layout' : '' ); ?>">
150 <?php foreach ( $this->options as $i => $option ) { ?>
151 <label class="srfm-<?php echo esc_attr( $this->slug ); ?>-single">
152 <input type="<?php echo esc_attr( $this->type_attr ); ?>" id="srfm-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id . '-' . $i ); ?>" class="srfm-input-<?php echo esc_attr( $this->slug ); ?>-single" <?php echo wp_kses_post( $this->name_attr ); ?>/>
153 <div class="srfm-block-content-wrap">
154 <div class="srfm-option-container">
155 <?php if ( 'icon' === $this->option_type && ! empty( $option['icon'] ) ) { ?>
156 <span class="srfm-option-icon">
157 <?php Spec_Gb_Helper::render_svg_html( $option['icon'] ); ?>
158 </span>
159 <?php } elseif ( 'image' === $this->option_type && ! empty( $option['image'] ) ) { ?>
160 <span class="srfm-option-image">
161 <img src="<?php echo esc_url( $option['image'] ); ?>"/>
162 </span>
163 <?php } ?>
164 <p><?php echo isset( $option['optionTitle'] ) ? esc_html( $option['optionTitle'] ) : ''; ?></p>
165 </div>
166 <div class="srfm-icon-container"><?php echo $check_svg . $unchecked_svg; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Ignored to render svg ?></div>
167 </div>
168 </label>
169 <?php } ?>
170 </div>
171 <?php } ?>
172 <div class="srfm-error-wrap"><?php echo wp_kses_post( $this->error_msg_markup ); ?></div>
173 </fieldset>
174 </div>
175 <?php
176 return ob_get_clean();
177
178 }
179 }
180