| 1 |
<?php |
| 2 |
/** |
| 3 |
* Form Field Text block. |
| 4 |
* |
| 5 |
* @package ghostkit |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* Class GhostKit_Form_Field_Text_Block |
| 14 |
*/ |
| 15 |
class GhostKit_Form_Field_Text_Block { |
| 16 |
/** |
| 17 |
* GhostKit_Form_Field_Text_Block constructor. |
| 18 |
*/ |
| 19 |
public function __construct() { |
| 20 |
add_action( 'init', array( $this, 'init' ) ); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Init. |
| 25 |
*/ |
| 26 |
public function init() { |
| 27 |
register_block_type_from_metadata( |
| 28 |
dirname( __FILE__ ), |
| 29 |
array( |
| 30 |
'render_callback' => array( $this, 'block_render' ), |
| 31 |
'attributes' => GhostKit_Form_Field_Attributes::get_block_attributes( |
| 32 |
array( |
| 33 |
'label' => array( |
| 34 |
'default' => esc_html__( 'Text', 'ghostkit' ), |
| 35 |
), |
| 36 |
) |
| 37 |
), |
| 38 |
) |
| 39 |
); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Register gutenberg block output |
| 44 |
* |
| 45 |
* @param array $attributes - block attributes. |
| 46 |
* |
| 47 |
* @return string |
| 48 |
*/ |
| 49 |
public function block_render( $attributes ) { |
| 50 |
ob_start(); |
| 51 |
|
| 52 |
$class = 'ghostkit-form-field ghostkit-form-field-text'; |
| 53 |
|
| 54 |
if ( isset( $attributes['className'] ) ) { |
| 55 |
$class .= ' ' . $attributes['className']; |
| 56 |
} |
| 57 |
|
| 58 |
?> |
| 59 |
|
| 60 |
<div class="<?php echo esc_attr( $class ); ?>"> |
| 61 |
<?php GhostKit_Form_Field_Label::get( $attributes ); ?> |
| 62 |
|
| 63 |
<input type="text" <?php GhostKit_Form_Field_Attributes::get( $attributes ); ?> /> |
| 64 |
|
| 65 |
<?php GhostKit_Form_Field_Description::get( $attributes ); ?> |
| 66 |
</div> |
| 67 |
|
| 68 |
<?php |
| 69 |
|
| 70 |
return ob_get_clean(); |
| 71 |
} |
| 72 |
} |
| 73 |
new GhostKit_Form_Field_Text_Block(); |
| 74 |
|