| @@ -18,8 +18,16 @@ | ||
| 18 | 18 | * @since 0.0.1 |
| 19 | 19 | */ |
| 20 | 20 | class Url_Markup extends Base { |
| 21 | 21 | /** |
| 22 | + * Read-only attribute for the URL field. | |
| 23 | + * | |
| 24 | + * @var bool | |
| 25 | + * @since 1.7.2 | |
| 26 | + */ | |
| 27 | + protected $read_only; | |
| 28 | + | |
| 29 | + /** | |
| 22 | 30 | * Initialize the properties based on block attributes. |
| 23 | 31 | * |
| 24 | 32 | * @param array<mixed> $attributes Block attributes. |
| 25 | 33 | * @since 0.0.2 |
| @@ -26,10 +34,11 @@ | ||
| 26 | 34 | */ |
| 27 | 35 | public function __construct( $attributes ) { |
| 28 | 36 | $this->slug = 'url'; |
| 29 | 37 | $this->set_properties( $attributes ); |
| 30 | - $this->set_input_label( __( 'Url', 'sureforms' ) ); | |
| 38 | + $this->set_input_label( __( 'URL', 'sureforms' ) ); | |
| 31 | 39 | $this->set_error_msg( $attributes, 'srfm_url_block_required_text' ); |
| 40 | + $this->read_only = ! empty( trim( $this->default ) ) && $attributes['readOnly']; | |
| 32 | 41 | $this->set_unique_slug(); |
| 33 | 42 | $this->set_field_name( $this->unique_slug ); |
| 34 | 43 | $this->set_markup_properties( $this->input_label, true ); |
| 35 | 44 | $this->set_aria_described_by(); |
| @@ -39,20 +48,19 @@ | ||
| 39 | 48 | /** |
| 40 | 49 | * Render the sureforms url classic styling |
| 41 | 50 | * |
| 42 | 51 | * @since 0.0.2 |
| 43 | - * @return string|boolean | |
| 52 | + * @return string|bool | |
| 44 | 53 | */ |
| 45 | 54 | public function markup() { |
| 46 | 55 | 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<?php echo esc_attr( $this->block_width ); ?><?php echo esc_attr( $this->class_name ); ?> <?php echo esc_attr( $this->conditional_class ); ?>"> | |
| 56 | + <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 ); ?><?php echo esc_attr( $this->read_only ? ' srfm-read-only' : '' ); ?>"> | |
| 48 | 57 | <?php echo wp_kses_post( $this->label_markup ); ?> |
| 49 | 58 | <?php echo wp_kses_post( $this->help_markup ); ?> |
| 50 | 59 | <div class="srfm-block-wrap"> |
| 51 | 60 | <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 ); ?>" |
| 52 | 61 | <?php echo ! empty( $this->aria_described_by ) ? "aria-describedby='" . esc_attr( trim( $this->aria_described_by ) ) . "'" : ''; ?> |
| 53 | - aria-required="<?php echo esc_attr( $this->aria_require_attr ); ?>" <?php echo wp_kses_post( $this->default_value_attr ); ?> <?php echo wp_kses_post( $this->placeholder_attr ); ?>/> | |
| 54 | - <?php echo $this->error_svg; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Ignored to render svg ?> | |
| 62 | + data-required="<?php echo esc_attr( $this->data_require_attr ); ?>" aria-required="<?php echo esc_attr( $this->data_require_attr ); ?>" value="<?php echo esc_attr( $this->default ); ?>" <?php echo wp_kses_post( $this->placeholder_attr ); ?> <?php echo $this->read_only ? 'readonly' : ''; ?> /> | |
| 55 | 63 | </div> |
| 56 | 64 | <div class="srfm-error-wrap"> |
| 57 | 65 | <?php echo wp_kses_post( $this->error_msg_markup ); ?> |
| 58 | 66 | </div> |
| @@ -60,5 +68,4 @@ | ||
| 60 | 68 | <?php |
| 61 | 69 | return ob_get_clean(); |
| 62 | 70 | } |
| 63 | 71 | } |
| 64 | - | |