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 / dropdown-markup.php

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

129 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 use Spec_Gb_Helper;
13 use SRFM\Inc\Helper;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 /**
20 * Sureforms Dropdown Markup Class.
21 *
22 * @since 0.0.1
23 */
24 class Dropdown_Markup extends Base {
25
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 /**
63 * Data attribute markup for min and max value
64 *
65 * @since 0.0.13
66 * @return string
67 */
68 protected function data_attribute_markup() {
69 $data_attr = '';
70 if ( 'false' === $this->multi_select_attr ) {
71 return '';
72 }
73
74 if ( $this->min_selection ) {
75 $data_attr .= 'data-min-selection="' . esc_attr( $this->min_selection ) . '"';
76 }
77 if ( $this->max_selection ) {
78 $data_attr .= 'data-max-selection="' . esc_attr( $this->max_selection ) . '"';
79 }
80
81 return $data_attr;
82 }
83
84 /**
85 * Render the sureforms dropdown classic styling
86 *
87 * @since 0.0.2
88 * @return string|boolean
89 */
90 public function markup() {
91 ob_start(); ?>
92 <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 ); ?>">
93 <fieldset>
94 <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-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?><?php echo esc_attr( $this->field_name ); ?>" type="hidden" value=""/>
95 <legend>
96 <?php echo wp_kses_post( $this->label_markup ); ?>
97 <?php echo wp_kses_post( $this->help_markup ); ?>
98 </legend>
99 <div class="srfm-block-wrap srfm-dropdown-common-wrap">
100 <?php
101 if ( is_array( $this->options ) ) {
102 ?>
103 <select
104 class="srfm-dropdown-common srfm-<?php echo esc_attr( $this->slug ); ?>-input"
105 <?php echo ! empty( $this->aria_described_by ) ? "aria-describedby='" . esc_attr( trim( $this->aria_described_by ) ) . "'" : ''; ?>
106 aria-required="<?php echo esc_attr( $this->aria_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">
107 <option class="srfm-dropdown-placeholder" value="" disabled selected><?php echo esc_html( $this->placeholder ); ?></option>
108 <?php foreach ( $this->options as $option ) { ?>
109 <?php
110 $icon_svg = Spec_Gb_Helper::render_svg_html( isset( $option['icon'] ) ? $option['icon'] : '', true );
111 $escaped_icon_svg = htmlspecialchars( Helper::get_string_value( $icon_svg ), ENT_QUOTES, 'UTF-8' );
112 ?>
113 <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>
114 <?php
115 }
116 ?>
117 </select>
118 <?php } ?>
119 </div>
120 <div class="srfm-error-wrap">
121 <?php echo wp_kses_post( $this->error_msg_markup ); ?>
122 </div>
123 </fieldset>
124 </div>
125 <?php
126 return ob_get_clean();
127 }
128 }
129