base-function.php
62 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Blocks\Conditional_Block\Functions; |
| 5 | |
| 6 | use Jet_Form_Builder\Blocks\Conditional_Block\Condition_Response_Object; |
| 7 | use Jet_Form_Builder\Blocks\Conditional_Block\Condition_Types\Base_Condition_Type; |
| 8 | use Jet_Form_Builder\Classes\Arrayable\Arrayable; |
| 9 | use JFB_Components\Repository\Repository_Item_Instance_Trait; |
| 10 | use Jet_Form_Builder\Classes\Tools; |
| 11 | |
| 12 | // If this file is called directly, abort. |
| 13 | if ( ! defined( 'WPINC' ) ) { |
| 14 | die; |
| 15 | } |
| 16 | |
| 17 | abstract class Base_Function implements |
| 18 | Repository_Item_Instance_Trait, |
| 19 | Arrayable, |
| 20 | Condition_Response_Object { |
| 21 | |
| 22 | abstract public function get_id(): string; |
| 23 | |
| 24 | abstract public function get_title(): string; |
| 25 | |
| 26 | public function get_display(): string { |
| 27 | return ''; |
| 28 | } |
| 29 | |
| 30 | public function rep_item_id() { |
| 31 | return $this->get_id(); |
| 32 | } |
| 33 | |
| 34 | public function to_response( array $base, Base_Condition_Type $item ): array { |
| 35 | return array(); |
| 36 | } |
| 37 | |
| 38 | public function to_string( array $settings ): string { |
| 39 | $slug = $this->get_id(); |
| 40 | $current = $settings[ $slug ] ?? array(); |
| 41 | |
| 42 | if ( empty( $current ) ) { |
| 43 | return $slug; |
| 44 | } |
| 45 | |
| 46 | return Tools::esc_attr( |
| 47 | array( |
| 48 | $slug => $current, |
| 49 | ) |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | public function to_array(): array { |
| 54 | return array( |
| 55 | 'value' => $this->get_id(), |
| 56 | 'label' => $this->get_title(), |
| 57 | 'display' => $this->get_display(), |
| 58 | ); |
| 59 | } |
| 60 | |
| 61 | } |
| 62 |