array( 'type' => 'string', 'default' => $this->get_default_value( 'label' ), ), 'required' => array( 'type' => 'boolean', 'default' => $this->get_default_value( 'required' ), ), // get_supports() style, color and typography attributes. 'align' => array( 'type' => 'string', ), 'style' => array( 'type' => 'object', ), 'backgroundColor' => array( 'type' => 'string', ), 'textColor' => array( 'type' => 'string', ), 'fontSize' => array( 'type' => 'string', ), // Always required for Gutenberg. 'is_gutenberg_example' => array( 'type' => 'boolean', 'default' => false, ), ); } /** * Returns this block's supported built-in Attributes. * * @since 3.0.0 * * @return array Supports */ public function get_supports() { return array( 'align' => true, 'className' => true, 'color' => array( 'link' => true, 'background' => true, 'text' => true, ), 'typography' => array( 'fontSize' => true, 'lineHeight' => true, ), 'spacing' => array( 'margin' => true, 'padding' => true, ), ); } /** * Returns this block's Fields * * @since 3.0.0 * * @return bool|array */ public function get_fields() { return array( 'label' => array( 'label' => __( 'Label', 'convertkit' ), 'type' => 'text', 'description' => __( 'The field label.', 'convertkit' ), ), 'required' => array( 'label' => __( 'Required', 'convertkit' ), 'type' => 'toggle', 'description' => __( 'Whether the field is required.', 'convertkit' ), ), ); } /** * Returns this block's UI panels / sections. * * @since 3.0.0 * * @return bool|array */ public function get_panels() { return array( 'general' => array( 'label' => __( 'General', 'convertkit' ), 'fields' => array( 'label', 'required', ), ), ); } /** * Returns this block's Default Values * * @since 3.0.0 * * @return array */ public function get_default_values() { return array( 'label' => '', 'required' => true, // Built-in Gutenberg block attributes. 'style' => '', 'backgroundColor' => '', 'textColor' => '', ); } /** * Returns the block's output, based on the supplied configuration attributes. * * @since 3.0.0 * * @param array $atts Block Attributes. * @return string Output */ public function render( $atts ) { // Parse attributes, defining fallback defaults if required // and moving some attributes (such as Gutenberg's styles), if defined. $atts = $this->sanitize_and_declare_atts( $atts ); // Get CSS classes and styles. $css_classes = $this->get_css_classes( array( 'wp-block-convertkit-form-builder-field', 'convertkit-form-builder-field' ) ); $css_styles = $this->get_css_styles( $atts ); // Determine if the field is required. $field_required = $this->field_required ? true : ( $atts['required'] ? true : false ); // Build input / textarea. switch ( $this->field_type ) { case 'textarea': $field = sprintf( '', esc_attr( sanitize_title( $this->field_id ) ), esc_attr( $this->field_name ), $field_required ? ' required' : '' ); break; default: $field = sprintf( '', esc_attr( $this->field_type ), esc_attr( sanitize_title( $this->field_id ) ), esc_attr( $this->field_name ), $field_required ? ' required' : '' ); break; } // Build field HTML. $html = sprintf( '
%s
', implode( ' ', map_deep( $css_classes, 'sanitize_html_class' ) ), implode( ';', map_deep( $css_styles, 'esc_attr' ) ), esc_attr( sanitize_title( $this->field_id ) ), esc_html( $atts['label'] ), ( $field_required ? ' *' : '' ), $field ); /** * Filter the block's content immediately before it is output. * * @since 3.0.0 * * @param string $html Field HTML. * @param array $atts Block Attributes. */ $html = apply_filters( 'convertkit_block_form_builder_field_render', $html, $atts ); return $html; } }