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