| 1 |
<?php |
| 2 |
/** |
| 3 |
* Sureforms Checkbox 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 Checkbox Markup Class. |
| 17 |
* |
| 18 |
* @since 0.0.1 |
| 19 |
*/ |
| 20 |
class Checkbox_Markup extends Base { |
| 21 |
/** |
| 22 |
* Initialize the properties based on block attributes. |
| 23 |
* |
| 24 |
* @param array<mixed> $attributes Block attributes. |
| 25 |
* @since 0.0.2 |
| 26 |
*/ |
| 27 |
public function __construct( $attributes ) { |
| 28 |
$this->set_properties( $attributes ); |
| 29 |
$this->set_input_label( __( 'Checkbox', 'sureforms' ) ); |
| 30 |
$this->set_error_msg( $attributes, 'srfm_checkbox_block_required_text' ); |
| 31 |
$this->slug = 'checkbox'; |
| 32 |
$this->set_markup_properties(); |
| 33 |
$this->set_aria_described_by(); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Render the sureforms checkbox classic styling |
| 38 |
* |
| 39 |
* @since 0.0.2 |
| 40 |
* @return string|bool |
| 41 |
*/ |
| 42 |
public function markup() { |
| 43 |
|
| 44 |
$label_random_id = 'srfm-' . $this->slug . '-' . wp_rand(); |
| 45 |
|
| 46 |
ob_start(); ?> |
| 47 |
<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 ); ?>"> |
| 48 |
<div class="srfm-block-wrap"> |
| 49 |
<input class="srfm-input-common screen-reader-text srfm-input-<?php echo esc_attr( $this->slug ); ?>" id="<?php echo esc_attr( $label_random_id ); ?>" |
| 50 |
<?php echo ! empty( $this->aria_described_by ) ? "aria-describedby='" . esc_attr( trim( $this->aria_described_by ) ) . "'" : ''; ?> |
| 51 |
name="srfm-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?><?php echo esc_attr( $this->field_name ); ?>" data-required="<?php echo esc_attr( $this->data_require_attr ); ?>" aria-required="<?php echo esc_attr( $this->data_require_attr ); ?>" type="checkbox" <?php echo esc_attr( $this->checked_attr ); ?>/> |
| 52 |
<label class="srfm-cbx" for="<?php echo esc_attr( $label_random_id ); ?>"> |
| 53 |
<span class="srfm-span-wrap"> |
| 54 |
<svg class="srfm-check-icon" width="12px" height="10px" aria-hidden="true"> |
| 55 |
<use xlink:href="#srfm-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?>-check"></use> |
| 56 |
</svg> |
| 57 |
</span> |
| 58 |
<span class="srfm-span-wrap srfm-block-label"><?php echo wp_kses( $this->label, $this->allowed_tags ); ?> |
| 59 |
<?php if ( $this->required ) { ?> |
| 60 |
<span class="srfm-required" aria-hidden="true"> *</span> |
| 61 |
<?php } ?> |
| 62 |
</span> |
| 63 |
</label> |
| 64 |
<svg class="srfm-inline-svg" aria-hidden="true"> |
| 65 |
<symbol id="srfm-<?php echo esc_attr( $this->slug ); ?>-<?php echo esc_attr( $this->block_id ); ?>-check" viewbox="0 0 12 10"> |
| 66 |
<polyline points="1.5 6 4.5 9 10.5 1"></polyline> |
| 67 |
</symbol> |
| 68 |
</svg> |
| 69 |
</div> |
| 70 |
<?php echo wp_kses_post( $this->help_markup ); ?> |
| 71 |
<div class="srfm-error-wrap"> |
| 72 |
<?php echo wp_kses_post( $this->error_msg_markup ); ?> |
| 73 |
</div> |
| 74 |
</div> |
| 75 |
<?php |
| 76 |
$markup = ob_get_clean(); |
| 77 |
|
| 78 |
return apply_filters( |
| 79 |
'srfm_block_field_markup', |
| 80 |
$markup, |
| 81 |
[ |
| 82 |
'slug' => $this->slug, |
| 83 |
'is_editing' => $this->is_editing, |
| 84 |
'field_name' => $this->field_name, |
| 85 |
'attributes' => $this->attributes, |
| 86 |
] |
| 87 |
); |
| 88 |
} |
| 89 |
|
| 90 |
} |
| 91 |
|