base-function.php
3 years ago
function-hide.php
3 years ago
function-set-value.php
3 years ago
function-show.php
3 years ago
function-show.php
44 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Blocks\Conditional_Block\Functions; |
| 5 | |
| 6 | |
| 7 | use Jet_Form_Builder\Blocks\Conditional_Block\Condition_Item; |
| 8 | use Jet_Form_Builder\Blocks\Exceptions\Condition_Exception; |
| 9 | |
| 10 | class Function_Show extends Base_Function { |
| 11 | |
| 12 | const ID = 'show'; |
| 13 | |
| 14 | public function get_id(): string { |
| 15 | return self::ID; |
| 16 | } |
| 17 | |
| 18 | public function get_title(): string { |
| 19 | return __( 'Show this field if...', 'jet-form-builder' ); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * @param array $base |
| 24 | * @param Condition_Item $item |
| 25 | * |
| 26 | * @return array |
| 27 | * @throws Condition_Exception |
| 28 | */ |
| 29 | public function to_response( array $base, Condition_Item $item ): array { |
| 30 | $result = $base['check_result'] ?? null; |
| 31 | |
| 32 | // if operator not checked on server-side |
| 33 | if ( is_null( $result ) ) { |
| 34 | return array(); |
| 35 | } |
| 36 | |
| 37 | if ( ! $result ) { |
| 38 | throw new Condition_Exception( 'Because I can.' ); |
| 39 | } |
| 40 | |
| 41 | return array(); |
| 42 | } |
| 43 | |
| 44 | } |