$attributes Block attributes. * @since 0.0.1 */ public function __construct( $attributes ) { $this->slug = 'donation-amount'; $this->choice_type = isset( $attributes['choiceType'] ) ? Helper::get_string_value( $attributes['choiceType'] ) : 'radio'; $this->layout = isset( $attributes['layout'] ) ? Helper::get_string_value( $attributes['layout'] ) : 'horizontal'; $this->choice_width = isset( $attributes['choiceWidth'] ) ? Helper::get_string_value( $attributes['choiceWidth'] ) : '50'; $this->allow_custom_amount = ! isset( $attributes['allowCustomAmount'] ) || (bool) $attributes['allowCustomAmount']; $this->custom_amount_min = isset( $attributes['customAmountMin'] ) && is_numeric( $attributes['customAmountMin'] ) ? (float) $attributes['customAmountMin'] : 0.0; $this->custom_amount_max = isset( $attributes['customAmountMax'] ) && is_numeric( $attributes['customAmountMax'] ) ? (float) $attributes['customAmountMax'] : 0.0; $this->set_properties( $attributes ); $this->set_unique_slug(); $this->set_markup_properties(); } /** * Render donation-amount markup * * @since 0.0.1 * @return string */ public function markup() { $classes = $this->get_field_classes( [ 'sd-' . $this->choice_type . '-mode' ] ); $vertical_class = 'vertical' === $this->layout ? ' sd-vertical-layout' : ''; $choice_width_class = ' sd-choice-width-' . str_replace( '.', '-', $this->choice_width ); $wrap_class = 'sd-block-wrap sd-donation-amount-wrap' . $choice_width_class . $vertical_class; $svg_type = 'radio' === $this->choice_type ? 'circle' : 'square'; $checked_svg = $this->get_svg_icon( $svg_type . '-checked', 'sd-donation-amount-icon' ); $unchecked_svg = $this->get_svg_icon( $svg_type . '-unchecked', 'sd-donation-amount-icon-unchecked' ); $input_name = 'checkbox' === $this->choice_type ? $this->field_name . '[]' : $this->field_name; // Get the default value for the hidden input (preselected option). $hidden_value = ''; if ( ! empty( $this->default ) && ! empty( $this->options ) && is_array( $this->options ) ) { foreach ( $this->options as $option ) { $option_value = $option['value'] ?? ( $option['label'] ?? '' ); if ( $this->default === $option_value ) { $hidden_value = $option_value; break; } } } ob_start(); ?>