PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 0.0.11
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v0.0.11
2.12.8 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 All 98 releases
sureforms / inc / fields / multichoice-markup.php

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

158 lines 5.6 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 * Render the sureforms Multichoice classic styling
113 *
114 * @since 0.0.2
115 * @return string|boolean
116 */
117 public function markup() {
118 $check_svg = Helper::fetch_svg( $this->svg_type . '-checked', 'srfm-' . $this->slug . '-icon' );
119 $unchecked_svg = Helper::fetch_svg( $this->svg_type . '-unchecked', 'srfm-' . $this->slug . '-icon-unchecked' );
120 ob_start(); ?>
121 <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 ); ?>">
122 <fieldset>
123 <input class="srfm-input-<?php echo esc_attr( $this->slug ); ?>-hidden" aria-required="<?php echo esc_attr( $this->aria_require_attr ); ?>" 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=""/>
124 <legend><?php echo wp_kses_post( $this->label_markup ); ?></legend>
125 <?php echo wp_kses_post( $this->help_markup ); ?>
126 <?php if ( is_array( $this->options ) ) { ?>
127 <div class="srfm-block-wrap <?php echo esc_attr( $this->choice_width_attr ); ?> <?php echo( $this->vertical_layout ? 'srfm-vertical-layout' : '' ); ?>">
128 <?php foreach ( $this->options as $i => $option ) { ?>
129 <label class="srfm-<?php echo esc_attr( $this->slug ); ?>-single">
130 <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 ); ?>/>
131 <div class="srfm-block-content-wrap">
132 <div class="srfm-option-container">
133 <?php if ( 'icon' === $this->option_type && ! empty( $option['icon'] ) ) { ?>
134 <span class="srfm-option-icon">
135 <?php Spec_Gb_Helper::render_svg_html( $option['icon'] ); ?>
136 </span>
137 <?php } elseif ( 'image' === $this->option_type && ! empty( $option['image'] ) ) { ?>
138 <span class="srfm-option-image">
139 <img src="<?php echo esc_url( $option['image'] ); ?>"/>
140 </span>
141 <?php } ?>
142 <p><?php echo isset( $option['optionTitle'] ) ? esc_html( $option['optionTitle'] ) : ''; ?></p>
143 </div>
144 <div class="srfm-icon-container"><?php echo $check_svg . $unchecked_svg; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Ignored to render svg ?></div>
145 </div>
146 </label>
147 <?php } ?>
148 </div>
149 <?php } ?>
150 <div class="srfm-error-wrap"><?php echo wp_kses_post( $this->error_msg_markup ); ?></div>
151 </fieldset>
152 </div>
153 <?php
154 return ob_get_clean();
155
156 }
157 }
158