| 1 |
<?php |
| 2 |
|
| 3 |
namespace Jet_Form_Builder\Blocks\Render; |
| 4 |
|
| 5 |
// If this file is called directly, abort. |
| 6 |
use Jet_Form_Builder\Blocks\Button_Types\Button_Type_Base; |
| 7 |
use Jet_Form_Builder\Blocks\Types\Action_Button; |
| 8 |
use Jet_Form_Builder\Classes\Attributes_Trait; |
| 9 |
|
| 10 |
if ( ! defined( 'WPINC' ) ) { |
| 11 |
die; |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* Define text field renderer class |
| 16 |
* |
| 17 |
* @property Action_Button $block_type |
| 18 |
*/ |
| 19 |
class Action_Button_Render extends Base { |
| 20 |
|
| 21 |
/** |
| 22 |
* @var Attributes_Trait |
| 23 |
*/ |
| 24 |
public $wrapper; |
| 25 |
|
| 26 |
public function get_name() { |
| 27 |
return 'action-button'; |
| 28 |
} |
| 29 |
|
| 30 |
public function label_allowed() { |
| 31 |
return false; |
| 32 |
} |
| 33 |
|
| 34 |
public function before_render( $args ) { |
| 35 |
$type = $args['action_type'] ?? ''; |
| 36 |
$this->wrapper = new class() { |
| 37 |
use Attributes_Trait; |
| 38 |
}; |
| 39 |
|
| 40 |
/** @var Button_Type_Base $type */ |
| 41 |
$type = $this->block_type->get_button_type( $type ); |
| 42 |
|
| 43 |
if ( is_null( $type ) ) { |
| 44 |
return; |
| 45 |
} |
| 46 |
|
| 47 |
$this->add_attribute( 'class', 'jet-form-builder__action-button' ); |
| 48 |
$this->add_attribute( 'class', $args['class_name'] ?? '' ); |
| 49 |
$this->add_attribute( 'class', $type->get_class( 'button' ) ); |
| 50 |
$this->add_attribute( 'type', $type->get_type() ); |
| 51 |
|
| 52 |
$type->before_render( $this, $args ); |
| 53 |
|
| 54 |
$wrap_classes = array( |
| 55 |
'jet-form-builder__action-button-wrapper', |
| 56 |
$type->get_class( 'wrapper' ), |
| 57 |
); |
| 58 |
|
| 59 |
if ( isset( $args['add_prev'] ) && $args['add_prev'] && 1 < $this->block_type->get_current_form_break()->get_current() ) { |
| 60 |
$wrap_classes[] = 'has-prev'; |
| 61 |
} |
| 62 |
$this->wrapper->add_attribute( 'data-type', $type->slug() ); |
| 63 |
$this->wrapper->add_attribute( 'class', $wrap_classes ); |
| 64 |
} |
| 65 |
|
| 66 |
} |
| 67 |
|