Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 71 additions & 76 deletions projects/packages/forms/src/contact-form/class-contact-form-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,52 +103,53 @@ class Contact_Form_Field extends Contact_Form_Shortcode {
public function __construct( $attributes, $content = null, $form = null ) {
$attributes = shortcode_atts(
array(
'label' => null,
'togglelabel' => null,
'type' => 'text',
'required' => false,
'requiredtext' => null,
'options' => array(),
'optionsdata' => array(),
'id' => null,
'style' => null,
'fieldbackgroundcolor' => null,
'buttonbackgroundcolor' => null,
'buttonborderradius' => null,
'buttonborderwidth' => null,
'textcolor' => null,
'default' => null,
'values' => null,
'placeholder' => null,
'class' => null,
'width' => null,
'consenttype' => null,
'dateformat' => null,
'implicitconsentmessage' => null,
'explicitconsentmessage' => null,
'borderradius' => null,
'borderwidth' => null,
'lineheight' => null,
'labellineheight' => null,
'bordercolor' => null,
'inputcolor' => null,
'labelcolor' => null,
'labelfontsize' => null,
'fieldfontsize' => null,
'labelclasses' => null,
'labelstyles' => null,
'inputclasses' => null,
'inputstyles' => null,
'optionclasses' => null,
'optionstyles' => null,
'min' => null,
'max' => null,
'maxfiles' => null,
'fieldwrapperclasses' => null,
'outlinestyledata' => array(),
'outlinestyleclasses' => null,
'optionsclasses' => null,
'optionsstyles' => null,
'label' => null,
'togglelabel' => null,
'type' => 'text',
'required' => false,
'requiredtext' => null,
'options' => array(),
'optionsdata' => array(),
'id' => null,
'style' => null,
'fieldbackgroundcolor' => null,
'buttonbackgroundcolor' => null,
'buttonborderradius' => null,
'buttonborderwidth' => null,
'textcolor' => null,
'default' => null,
'values' => null,
'placeholder' => null,
'class' => null,
'width' => null,
'consenttype' => null,
'dateformat' => null,
'implicitconsentmessage' => null,
'explicitconsentmessage' => null,
'borderradius' => null,
'borderwidth' => null,
'lineheight' => null,
'labellineheight' => null,
'bordercolor' => null,
'inputcolor' => null,
'labelcolor' => null,
'labelfontsize' => null,
'fieldfontsize' => null,
'labelclasses' => null,
'labelstyles' => null,
'inputclasses' => null,
'inputstyles' => null,
'optionclasses' => null,
'optionstyles' => null,
'min' => null,
'max' => null,
'maxfiles' => null,
'fieldwrapperclasses' => null,
'stylevariationattributes' => array(),
'stylevariationclasses' => null,
'stylevariationstyles' => null,
Comment on lines 148 to 150

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

'optionsclasses' => null,
'optionsstyles' => null,
),
$attributes,
'contact-field'
Expand Down Expand Up @@ -830,19 +831,19 @@ public function render_radio_field( $id, $label, $value, $class, $required, $req
$fieldset_id = "id='" . esc_attr( "$id-label" ) . "'";

if ( $is_outlined_style ) {
$outline_styles = $this->get_attribute( 'outlinestyledata' );
$style_variation_attributes = $this->get_attribute( 'stylevariationattributes' );

if ( ! empty( $outline_styles ) ) {
$outline_styles = json_decode( html_entity_decode( $outline_styles, ENT_COMPAT ), true );
if ( ! empty( $style_variation_attributes ) ) {
$style_variation_attributes = json_decode( html_entity_decode( $style_variation_attributes, ENT_COMPAT ), true );
}

// When there's an outlined style, and border radius is set, the existing inline border radius is overridden to apply
// a limit of `100px` to the radius on the x axis. This achieves the same look and feel as other fields
// that use the notch html (`notched-label__leading` has a max-width of `100px` to prevent it from getting too wide).
// It prevents large border radius values from disrupting the look and feel of the fields.
if ( isset( $outline_styles['border']['radius'] ) ) {
if ( isset( $style_variation_attributes['border']['radius'] ) ) {
$options_styles = $options_styles ?? '';
$radius = $outline_styles['border']['radius'];
$radius = $style_variation_attributes['border']['radius'];
$has_split_radius_values = is_array( $radius );
$top_left_radius = $has_split_radius_values ? $radius['topLeft'] : $radius;
$top_right_radius = $has_split_radius_values ? $radius['topRight'] : $radius;
Expand Down Expand Up @@ -1233,19 +1234,19 @@ public function render_checkbox_multiple_field( $id, $label, $value, $class, $re
$fieldset_id = "id='" . esc_attr( "$id-label" ) . "'";

if ( $is_outlined_style ) {
$outline_styles = $this->get_attribute( 'outlinestyledata' );
$style_variation_attributes = $this->get_attribute( 'stylevariationattributes' );

if ( ! empty( $outline_styles ) ) {
$outline_styles = json_decode( html_entity_decode( $outline_styles, ENT_COMPAT ), true );
if ( ! empty( $style_variation_attributes ) ) {
$style_variation_attributes = json_decode( html_entity_decode( $style_variation_attributes, ENT_COMPAT ), true );
}

// When there's an outlined style, and border radius is set, the existing inline border radius is overridden to apply
// a limit of `100px` to the radius on the x axis. This achieves the same look and feel as other fields
// that use the notch html (`notched-label__leading` has a max-width of `100px` to prevent it from getting too wide).
// It prevents large border radius values from disrupting the look and feel of the fields.
if ( isset( $outline_styles['border']['radius'] ) ) {
if ( isset( $style_variation_attributes['border']['radius'] ) ) {
$options_styles = $options_styles ?? '';
$radius = $outline_styles['border']['radius'];
$radius = $style_variation_attributes['border']['radius'];
$has_split_radius_values = is_array( $radius );
$top_left_radius = $has_split_radius_values ? $radius['topLeft'] : $radius;
$top_right_radius = $has_split_radius_values ? $radius['topRight'] : $radius;
Expand Down Expand Up @@ -1543,23 +1544,17 @@ class=" ' . $classes . '"
* }
*/
private function get_form_variation_style_properties( $form_style = 'outlined' ) {
$style_attrs = '';
$css_vars = '';
$outline_styles = $this->get_attribute( 'outlinestyledata' );
$outline_classes = $this->get_attribute( 'outlinestyleclasses' );
$block_name = 'jetpack/input';
$css_vars = '';
$variation_attributes = $this->get_attribute( 'stylevariationattributes' );
$variation_attributes = ! empty( $variation_attributes ) ? json_decode( html_entity_decode( $variation_attributes, ENT_COMPAT ), true ) : array();
$variation_classes = $this->get_attribute( 'stylevariationclasses' );
$variation_style = $this->get_attribute( 'stylevariationstyles' );
$block_name = 'jetpack/input';

if ( $this->maybe_override_type() === 'radio' || $this->maybe_override_type() === 'checkbox-multiple' ) {
$block_name = 'jetpack/options';
}

$outline_styles = ! empty( $outline_styles ) ? json_decode( html_entity_decode( $outline_styles, ENT_COMPAT ), true ) : array();
$input_styles = $this->get_attribute( 'inputstyles' );

if ( ! empty( $input_styles ) ) {
$style_attrs = $input_styles;
}
Comment on lines 1559 to 1561

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where the bug was. I've removed it in favor of stylevariationstyles that are generated during shortcode rendering. (see my next comment for where that happens).


$global_styles = wp_get_global_styles(
array( 'border' ),
array(
Expand All @@ -1575,28 +1570,28 @@ private function get_form_variation_style_properties( $form_style = 'outlined' )
* For newer forms that use global styles or the block supports styles, this value will be empty and is ignored.
*/
$border_width_attribute = $this->get_attribute( 'borderwidth' );
$legacy_border_size = ! empty( $border_width_attribute ) || $border_width_attribute === '0' ? $border_width_attribute . 'px' : $outline_styles['border']['width'] ?? null;
$legacy_border_size = ! empty( $border_width_attribute ) || $border_width_attribute === '0' ? $border_width_attribute . 'px' : $variation_attributes['border']['width'] ?? null;
$legacy_border_size = is_numeric( $legacy_border_size ) ? $legacy_border_size . 'px' : $legacy_border_size;
$legacy_border_radius = $outline_styles['border']['radius'] ?? null;
$legacy_border_radius = $variation_attributes['border']['radius'] ?? null;
$legacy_border_radius = is_numeric( $legacy_border_radius ) ? $legacy_border_radius . 'px' : $legacy_border_radius;

$border_top_size = $legacy_border_size ??
$outline_styles['border']['top']['width'] ??
$variation_attributes['border']['top']['width'] ??
$global_styles['width'] ??
$global_styles['top']['width'] ?? null;

$border_right_size = $legacy_border_size ??
$outline_styles['border']['right']['width'] ??
$variation_attributes['border']['right']['width'] ??
$global_styles['width'] ??
$global_styles['right']['width'] ?? null;

$border_bottom_size = $legacy_border_size ??
$outline_styles['border']['bottom']['width'] ??
$variation_attributes['border']['bottom']['width'] ??
$global_styles['width'] ??
$global_styles['bottom']['width'] ?? null;

$border_left_size = $legacy_border_size ??
$outline_styles['border']['left']['width'] ??
$variation_attributes['border']['left']['width'] ??
$global_styles['width'] ??
$global_styles['left']['width'] ?? null;

Expand Down Expand Up @@ -1628,9 +1623,9 @@ private function get_form_variation_style_properties( $form_style = 'outlined' )
}

return array(
'style' => $style_attrs,
'style' => $variation_style,
'css_vars' => $css_vars,
'class_name' => $outline_classes,
'class_name' => $variation_classes,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,8 @@ public static function block_attributes_to_shortcode_attributes( $atts, $type, $
/*
Borders for the outlined notched HTML.
*/
$outlined_style_data = self::get_outlined_style_attributes( $block_name, $inner_block['attrs'] );
$atts['outlinestyledata'] = $outlined_style_data['outlinestyledata'] ?? null;
$atts['outlinestyleclasses'] = $outlined_style_data['outlinestyleclasses'] ?? null;
$style_variation_data = self::get_style_variation_shortcode_attributes( $block_name, $inner_block['attrs'] );
$atts = array_merge( $atts, $style_variation_data );
$add_block_style_classes_to_field_wrapper = true;
}

Expand Down Expand Up @@ -523,9 +522,8 @@ public static function block_attributes_to_shortcode_attributes( $atts, $type, $
/*
Borders for the outlined notched HTML.
*/
$outlined_style_data = self::get_outlined_style_attributes( $block_name, $inner_block['attrs'] );
$atts['outlinestyledata'] = $outlined_style_data['outlinestyledata'];
$atts['outlinestyleclasses'] = $outlined_style_data['outlinestyleclasses'];
$style_variation_atts = self::get_style_variation_shortcode_attributes( $block_name, $inner_block['attrs'] );
$atts = array_merge( $atts, $style_variation_atts );
$add_block_style_classes_to_field_wrapper = true;
}
}
Expand All @@ -552,38 +550,41 @@ public static function block_attributes_to_shortcode_attributes( $atts, $type, $

/**
* Returns the form "Outlined" style classes and styles.
* Important: The "Outlined" style is somewhat different as it uses custom HTML to create a border around the field.
* Important: The "Outlined" style is somewhat different as it uses custom HTML to create a border around the field's label.
* When applying styles to the control, background and border styles are applied to the custom HTML, not the input itself.
*
* @param string $block_name - the block name.
* @param array $attrs - the block attributes.
*
* @return array
*/
protected static function get_outlined_style_attributes( $block_name, $attrs ) {
$outlined_style_data = array();
$attributes_for_outlined_style = array();
protected static function get_style_variation_shortcode_attributes( $block_name, $attrs ) {
$picked_attributes = array();

// For style variations like the outlined style, we only care about porting specific attributes like background color and border
// to the custom label HTML, so we pick those attributes and ignore the rest.
if ( isset( $attrs['backgroundColor'] ) ) {
$attributes_for_outlined_style['backgroundColor'] = $attrs['backgroundColor'];
$picked_attributes['backgroundColor'] = $attrs['backgroundColor'];
}

if ( isset( $attrs['style']['border'] ) ) {
$attributes_for_outlined_style['style']['border'] = $attrs['style']['border'];
$picked_attributes['style']['border'] = $attrs['style']['border'];
}

if ( isset( $attrs['borderColor'] ) ) {
$attributes_for_outlined_style['borderColor'] = $attrs['borderColor'];
$picked_attributes['borderColor'] = $attrs['borderColor'];
}

if ( isset( $attrs['style']['color']['background'] ) ) {
$attributes_for_outlined_style['style']['color']['background'] = $attrs['style']['color']['background'];
$picked_attributes['style']['color']['background'] = $attrs['style']['color']['background'];
}

$outlined_attrs = self::get_block_support_classes_and_styles( $block_name, $attributes_for_outlined_style );
$outlined_style_data['outlinestyledata'] = isset( $attributes_for_outlined_style['style'] ) ? \wp_json_encode( $attributes_for_outlined_style['style'] ) : '';
$outlined_style_data['outlinestyleclasses'] = isset( $outlined_attrs['class'] ) ? ' ' . $outlined_attrs['class'] : '';
return $outlined_style_data;
$block_support_styles = self::get_block_support_classes_and_styles( $block_name, $picked_attributes );
return array(
'stylevariationattributes' => isset( $picked_attributes['style'] ) ? \wp_json_encode( $picked_attributes['style'] ) : '',
'stylevariationclasses' => isset( $block_support_styles['class'] ) ? ' ' . $block_support_styles['class'] : '',
'stylevariationstyles' => isset( $block_support_styles['style'] ) ? $block_support_styles['style'] : '',
);
Comment on lines 582 to 587

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where stylevariationstyles is generated by get_block_support_classes_and_styles.

}

/**
Expand Down
Loading