advanced-rules
2 years ago
button-types
2 years ago
conditional-block
2 years ago
exceptions
2 years ago
modules
2 years ago
render
2 years ago
ssr-validation
2 years ago
types
2 years ago
validation-messages
2 years ago
action-buttons-manager.php
2 years ago
block-helper.php
2 years ago
blocks-repository-base.php
2 years ago
default-blocks-repository.php
2 years ago
dynamic-value.php
2 years ago
form-builder-blocks-repository.php
2 years ago
module.php
2 years ago
native-block-wrapper-attributes.php
2 years ago
validation.php
2 years ago
action-buttons-manager.php
85 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Blocks; |
| 5 | |
| 6 | use Jet_Form_Builder\Blocks\Button_Types\Button_Type_Base; |
| 7 | |
| 8 | // If this file is called directly, abort. |
| 9 | if ( ! defined( 'WPINC' ) ) { |
| 10 | die; |
| 11 | } |
| 12 | |
| 13 | /** |
| 14 | * CRUD |
| 15 | * |
| 16 | * Trait Action_Buttons_Manager |
| 17 | * |
| 18 | * @package Jet_Form_Builder\Blocks |
| 19 | */ |
| 20 | trait Action_Buttons_Manager { |
| 21 | |
| 22 | /** |
| 23 | * @var Button_Type_Base[] |
| 24 | */ |
| 25 | private $button_types = array(); |
| 26 | |
| 27 | public function get_button_types() { |
| 28 | return $this->button_types; |
| 29 | } |
| 30 | |
| 31 | public function get_button_types_for_js() { |
| 32 | $prepared = array(); |
| 33 | |
| 34 | /** @var Button_Type_Base $type */ |
| 35 | foreach ( $this->get_button_types() as $type ) { |
| 36 | $prepared[] = array( |
| 37 | 'value' => $type->slug(), |
| 38 | 'label' => $type->label(), |
| 39 | 'button_class' => $type->get_class( 'button' ), |
| 40 | 'wrapper_class' => $type->get_class( 'wrapper' ), |
| 41 | ); |
| 42 | } |
| 43 | |
| 44 | return $prepared; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @param Button_Type_Base $button |
| 49 | * @param bool $update |
| 50 | */ |
| 51 | public function set_button_type( Button_Type_Base $button, $update = false ) { |
| 52 | if ( ! $update && $this->isset_button_type( $button->slug() ) ) { |
| 53 | return; |
| 54 | } |
| 55 | $this->button_types[ $button->slug() ] = $button; |
| 56 | } |
| 57 | |
| 58 | public function update_button_type( Button_Type_Base $button ) { |
| 59 | $this->set_button_type( $button, true ); |
| 60 | } |
| 61 | |
| 62 | public function isset_button_type( string $slug ) { |
| 63 | return isset( $this->button_types[ $slug ] ); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * @param $slug |
| 68 | * |
| 69 | * @return Button_Type_Base |
| 70 | */ |
| 71 | public function get_button_type( $slug ) { |
| 72 | return $this->button_types[ $slug ]; |
| 73 | } |
| 74 | |
| 75 | public function delete_button_type( $slug ) { |
| 76 | if ( ! $this->isset_button_type( $slug ) ) { |
| 77 | return false; |
| 78 | } |
| 79 | unset( $this->button_types[ $slug ] ); |
| 80 | |
| 81 | return true; |
| 82 | } |
| 83 | |
| 84 | } |
| 85 |