array( $this, 'block_render' ), 'attributes' => GhostKit_Form_Field_Attributes::get_block_attributes( array( 'label' => array( 'default' => esc_html__( 'Select', 'ghostkit' ), ), 'options' => array( 'type' => 'array', 'items' => array( 'type' => 'object', ), ), 'multiple' => array( 'type' => 'boolean', ), ) ), ) ); } /** * Register gutenberg block output * * @param array $attributes - block attributes. * * @return string */ public function block_render( $attributes ) { $attributes = array_merge( array( 'options' => array(), 'multiple' => false, ), $attributes ); $options = $attributes['options']; if ( ! is_array( $options ) ) { $options = array(); } // Add null option. if ( ! $attributes['multiple'] ) { $add_null_option = true; foreach ( $options as $data ) { if ( $data['selected'] ) { $add_null_option = false; } } if ( $add_null_option ) { array_unshift( $options, array( 'label' => esc_attr__( '--- Select ---', 'ghostkit' ), 'value' => '', 'selected' => true, ) ); } } ob_start(); $class = 'ghostkit-form-field ghostkit-form-field-select'; if ( isset( $attributes['className'] ) ) { $class .= ' ' . $attributes['className']; } ?>