base-render-state.php
2 years ago
custom-render-state.php
2 years ago
default-state.php
2 years ago
render-state-replace-exception.php
2 years ago
base-render-state.php
66 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Blocks\Conditional_Block\Render_States; |
| 5 | |
| 6 | use Jet_Form_Builder\Blocks\Conditional_Block\Render_State; |
| 7 | use Jet_Form_Builder\Classes\Arrayable\Arrayable; |
| 8 | use Jet_Form_Builder\Classes\Arrayable\Collection_Item_Interface; |
| 9 | use JFB_Components\Repository\Repository_Item_Instance_Trait; |
| 10 | |
| 11 | // If this file is called directly, abort. |
| 12 | if ( ! defined( 'WPINC' ) ) { |
| 13 | die; |
| 14 | } |
| 15 | |
| 16 | abstract class Base_Render_State implements |
| 17 | Repository_Item_Instance_Trait, |
| 18 | Collection_Item_Interface, |
| 19 | Arrayable { |
| 20 | |
| 21 | abstract public function get_title(): string; |
| 22 | |
| 23 | abstract public function is_supported(): bool; |
| 24 | |
| 25 | public function is_supported_on_current(): bool { |
| 26 | return $this->is_supported(); |
| 27 | } |
| 28 | |
| 29 | public function rep_item_id() { |
| 30 | return $this->get_id(); |
| 31 | } |
| 32 | |
| 33 | public function render(): string { |
| 34 | return sprintf( |
| 35 | '<input type="hidden" name="%1$s[]" value="%2$s" data-jfb-sync />', |
| 36 | Render_State::FIELD_NAME, |
| 37 | $this->get_id() |
| 38 | ); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Determines the availability of this state for switching |
| 43 | * to it using the Action Button |
| 44 | * |
| 45 | * @return bool |
| 46 | */ |
| 47 | public function can_be_switched(): bool { |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | public function exclude_states(): array { |
| 52 | return array( |
| 53 | Default_State::class, |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | public function to_array(): array { |
| 58 | return array( |
| 59 | 'value' => $this->get_id(), |
| 60 | 'label' => $this->get_title(), |
| 61 | 'can_be_switched' => $this->can_be_switched(), |
| 62 | ); |
| 63 | } |
| 64 | |
| 65 | } |
| 66 |