| 1 |
<?php |
| 2 |
/** |
| 3 |
* Sureforms Number Markup Class file. |
| 4 |
* |
| 5 |
* @package sureforms. |
| 6 |
* @since 0.0.1 |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace SRFM\Inc\Fields; |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; // Exit if accessed directly. |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* Sureforms Number Field Markup Class. |
| 17 |
* |
| 18 |
* @since 0.0.1 |
| 19 |
*/ |
| 20 |
class Number_Markup extends Base { |
| 21 |
|
| 22 |
/** |
| 23 |
* Minimum value allowed for the input field. |
| 24 |
* |
| 25 |
* @var string |
| 26 |
* @since 0.0.2 |
| 27 |
*/ |
| 28 |
protected $min_value; |
| 29 |
|
| 30 |
/** |
| 31 |
* Maximum value allowed for the input field. |
| 32 |
* |
| 33 |
* @var string |
| 34 |
* @since 0.0.2 |
| 35 |
*/ |
| 36 |
protected $max_value; |
| 37 |
|
| 38 |
/** |
| 39 |
* Format type for the input field. |
| 40 |
* |
| 41 |
* @var string |
| 42 |
* @since 0.0.2 |
| 43 |
*/ |
| 44 |
protected $format_type; |
| 45 |
|
| 46 |
/** |
| 47 |
* HTML attribute string for the format type. |
| 48 |
* |
| 49 |
* @var string |
| 50 |
* @since 0.0.2 |
| 51 |
*/ |
| 52 |
protected $format_attr; |
| 53 |
|
| 54 |
/** |
| 55 |
* HTML attribute string for the minimum value. |
| 56 |
* |
| 57 |
* @var string |
| 58 |
* @since 0.0.2 |
| 59 |
*/ |
| 60 |
protected $min_value_attr; |
| 61 |
|
| 62 |
/** |
| 63 |
* HTML attribute string for the maximum value. |
| 64 |
* |
| 65 |
* @var string |
| 66 |
* @since 0.0.2 |
| 67 |
*/ |
| 68 |
protected $max_value_attr; |
| 69 |
|
| 70 |
/** |
| 71 |
* Initialize the properties based on block attributes. |
| 72 |
* |
| 73 |
* @param array<mixed> $attributes Block attributes. |
| 74 |
* @since 0.0.2 |
| 75 |
*/ |
| 76 |
public function __construct( $attributes ) { |
| 77 |
$this->set_properties( $attributes ); |
| 78 |
$this->slug = 'number'; |
| 79 |
$this->min_value = isset( $attributes['minValue'] ) ? $attributes['minValue'] : ''; |
| 80 |
$this->max_value = isset( $attributes['maxValue'] ) ? $attributes['maxValue'] : ''; |
| 81 |
$this->format_type = isset( $attributes['formatType'] ) ? $attributes['formatType'] : ''; |
| 82 |
$this->format_attr = $this->format_type ? ' format-type="' . $this->format_type . '" ' : ''; |
| 83 |
$this->min_value_attr = $this->min_value ? ' min="' . $this->min_value . '" ' : ''; |
| 84 |
$this->max_value_attr = $this->max_value ? ' max="' . $this->max_value . '" ' : ''; |
| 85 |
$this->set_input_label( __( 'Number', 'sureforms' ) ); |
| 86 |
$this->set_error_msg( $attributes, 'srfm_number_block_required_text' ); |
| 87 |
$this->set_unique_slug(); |
| 88 |
$this->set_field_name( $this->unique_slug ); |
| 89 |
$this->set_markup_properties( $this->input_label ); |
| 90 |
$this->set_aria_described_by(); |
| 91 |
$this->set_label_as_placeholder( $this->input_label ); |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* Render the sureforms number classic styling |
| 96 |
* |
| 97 |
* @since 0.0.2 |
| 98 |
* @return string|boolean |
| 99 |
*/ |
| 100 |
public function markup() { |
| 101 |
ob_start(); ?> |
| 102 |
<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<?php echo esc_attr( $this->block_width ); ?><?php echo esc_attr( $this->class_name ); ?> <?php echo esc_attr( $this->conditional_class ); ?>"> |
| 103 |
<?php echo wp_kses_post( $this->label_markup ); ?> |
| 104 |
<?php echo wp_kses_post( $this->help_markup ); ?> |
| 105 |
<div class="srfm-block-wrap"> |
| 106 |
<input class="srfm-input-common srfm-input-<?php echo esc_attr( $this->slug ); ?>" type="text" name="<?php echo esc_attr( $this->field_name ); ?>" id="<?php echo esc_attr( $this->unique_slug ); ?>" |
| 107 |
<?php echo ! empty( $this->aria_described_by ) ? "aria-describedby='" . esc_attr( trim( $this->aria_described_by ) ) . "'" : ''; ?> |
| 108 |
aria-required="<?php echo esc_attr( $this->aria_require_attr ); ?>" <?php echo wp_kses_post( $this->placeholder_attr . '' . $this->default_value_attr . '' . $this->format_attr . '' . $this->min_value_attr . '' . $this->max_value_attr ); ?> /> |
| 109 |
<?php echo $this->error_svg; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Ignored to render svg ?> |
| 110 |
</div> |
| 111 |
<div class="srfm-error-wrap"> |
| 112 |
<?php echo wp_kses_post( $this->error_msg_markup ); ?> |
| 113 |
</div> |
| 114 |
</div> |
| 115 |
<?php |
| 116 |
return ob_get_clean(); |
| 117 |
} |
| 118 |
|
| 119 |
} |
| 120 |
|