| 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 |
foreach ( $this->get_button_types() as $type ) { |
| 35 |
$prepared[] = array( |
| 36 |
'value' => $type->slug(), |
| 37 |
'button_class' => $type->get_class( 'button' ), |
| 38 |
'wrapper_class' => $type->get_class( 'wrapper' ), |
| 39 |
); |
| 40 |
} |
| 41 |
|
| 42 |
return $prepared; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* @param Button_Type_Base $button |
| 47 |
* @param bool $update |
| 48 |
*/ |
| 49 |
public function set_button_type( Button_Type_Base $button, $update = false ) { |
| 50 |
if ( ! $update && $this->isset_button_type( $button->slug() ) ) { |
| 51 |
return; |
| 52 |
} |
| 53 |
$this->button_types[ $button->slug() ] = $button; |
| 54 |
} |
| 55 |
|
| 56 |
public function update_button_type( Button_Type_Base $button ) { |
| 57 |
$this->set_button_type( $button, true ); |
| 58 |
} |
| 59 |
|
| 60 |
public function isset_button_type( string $slug ) { |
| 61 |
return isset( $this->button_types[ $slug ] ); |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* @param $slug |
| 66 |
* |
| 67 |
* @return Button_Type_Base |
| 68 |
*/ |
| 69 |
public function get_button_type( $slug ) { |
| 70 |
return $this->button_types[ $slug ]; |
| 71 |
} |
| 72 |
|
| 73 |
public function delete_button_type( $slug ) { |
| 74 |
if ( ! $this->isset_button_type( $slug ) ) { |
| 75 |
return false; |
| 76 |
} |
| 77 |
unset( $this->button_types[ $slug ] ); |
| 78 |
|
| 79 |
return true; |
| 80 |
} |
| 81 |
|
| 82 |
} |
| 83 |
|