PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 1.2.1
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v1.2.1
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 0.0.3 All 96 releases
sureforms / inc / fields / dropdown-markup.php

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

128 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Sureforms Dropdown Markup Class file.
4 *
5 * @package sureforms.
6 * @since 0.0.1
7 */
8
9 namespace SRFM\Inc\Fields;
10
11 require SRFM_DIR . 'modules/gutenberg/classes/class-spec-gb-helper.php';
12
13 use Spec_Gb_Helper;
14 use SRFM\Inc\Helper;
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit; // Exit if accessed directly.
18 }
19
20 /**
21 * Sureforms Dropdown Markup Class.
22 *
23 * @since 0.0.1
24 */
25 class Dropdown_Markup extends Base {
26 /**
27 * Stores the multi select attribute value.
28 *
29 * @var string
30 * @since 0.0.7
31 */
32 protected $multi_select_attr;
33
34 /**
35 * Stores the search attribute value.
36 *
37 * @var string
38 * @since 0.0.7
39 */
40 protected $search_attr;
41
42 /**
43 * Initialize the properties based on block attributes.
44 *
45 * @param array<mixed> $attributes Block attributes.
46 * @since 0.0.2
47 */
48 public function __construct( $attributes ) {
49 $this->set_properties( $attributes );
50 $this->set_input_label( __( 'Dropdown', 'sureforms' ) );
51 $this->set_error_msg( $attributes, 'srfm_dropdown_block_required_text' );
52 $this->slug = 'dropdown';
53 $this->multi_select_attr = ! empty( $attributes['multiSelect'] ) ? 'true' : 'false';
54 $this->search_attr = ! empty( $attributes['searchable'] ) ? 'true' : 'false';
55 $this->set_markup_properties();
56 $this->set_aria_described_by();
57 $this->set_label_as_placeholder( $this->input_label );
58 $this->placeholder = ! empty( $this->placeholder_attr ) ? $this->label : __( 'Select an option', 'sureforms' );
59 }
60
61 /**
62 * Render the sureforms dropdown classic styling
63 *
64 * @since 0.0.2
65 * @return string|bool
66 */
67 public function markup() {
68 ob_start(); ?>
69 <div data-block-id="<?php echo esc_attr( $this->block_id ); ?>" class="srfm-block-single srfm-block 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 esc_attr( $this->block_width ); ?><?php echo esc_attr( $this->class_name ); ?> <?php echo esc_attr( $this->conditional_class ); ?>">
70 <fieldset>
71 <input class="srfm-input-<?php echo esc_attr( $this->slug ); ?>-hidden" data-required="<?php echo esc_attr( $this->data_require_attr ); ?>" <?php echo wp_kses_post( $this->data_attribute_markup() ); ?> name="srfm-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?><?php echo esc_attr( $this->field_name ); ?>" type="hidden" value=""/>
72 <legend class="srfm-block-legend">
73 <?php echo wp_kses_post( $this->label_markup ); ?>
74 <?php echo wp_kses_post( $this->help_markup ); ?>
75 </legend>
76 <div class="srfm-block-wrap srfm-dropdown-common-wrap">
77 <?php
78 if ( is_array( $this->options ) ) {
79 ?>
80 <select
81 class="srfm-dropdown-common srfm-<?php echo esc_attr( $this->slug ); ?>-input"
82 <?php echo ! empty( $this->aria_described_by ) ? "aria-describedby='" . esc_attr( trim( $this->aria_described_by ) ) . "'" : ''; ?>
83 data-required="<?php echo esc_attr( $this->data_require_attr ); ?>" <?php echo wp_kses_post( $this->data_attribute_markup() ); ?> name="srfm-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?><?php echo esc_attr( $this->field_name ); ?>" data-multiple="<?php echo esc_attr( $this->multi_select_attr ); ?>" data-searchable="<?php echo esc_attr( $this->search_attr ); ?>" tabindex="0" aria-hidden="true">
84 <option class="srfm-dropdown-placeholder" value="" disabled selected><?php echo esc_html( $this->placeholder ); ?></option>
85 <?php foreach ( $this->options as $option ) { ?>
86 <?php
87 $icon_svg = Spec_Gb_Helper::render_svg_html( $option['icon'] ?? '', true );
88 $escaped_icon_svg = htmlspecialchars( Helper::get_string_value( $icon_svg ), ENT_QUOTES, 'UTF-8' );
89 ?>
90 <option value="<?php echo isset( $option['label'] ) ? esc_html( $option['label'] ) : ''; ?>" data-icon="<?php echo ! empty( $escaped_icon_svg ) ? esc_attr( $escaped_icon_svg ) : ''; ?>"><?php echo isset( $option['label'] ) ? esc_html( $option['label'] ) : ''; ?></option>
91 <?php
92 }
93 ?>
94 </select>
95 <?php } ?>
96 </div>
97 <div class="srfm-error-wrap">
98 <?php echo wp_kses_post( $this->error_msg_markup ); ?>
99 </div>
100 </fieldset>
101 </div>
102 <?php
103 return ob_get_clean();
104 }
105
106 /**
107 * Data attribute markup for min and max value
108 *
109 * @since 0.0.13
110 * @return string
111 */
112 protected function data_attribute_markup() {
113 $data_attr = '';
114 if ( 'false' === $this->multi_select_attr ) {
115 return '';
116 }
117
118 if ( $this->min_selection ) {
119 $data_attr .= 'data-min-selection="' . esc_attr( $this->min_selection ) . '"';
120 }
121 if ( $this->max_selection ) {
122 $data_attr .= 'data-max-selection="' . esc_attr( $this->max_selection ) . '"';
123 }
124
125 return $data_attr;
126 }
127 }
128