| 1 |
<?php |
| 2 |
|
| 3 |
namespace JFB_Modules\Option_Field\Blocks\Select; |
| 4 |
|
| 5 |
use Jet_Form_Builder\Blocks\Render\Base; |
| 6 |
|
| 7 |
// If this file is called directly, abort. |
| 8 |
if ( ! defined( 'WPINC' ) ) { |
| 9 |
die; |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* @property Block_Type $block_type |
| 14 |
* |
| 15 |
* Class Select_Field_Render |
| 16 |
* @package Jet_Form_Builder\Blocks\Render |
| 17 |
*/ |
| 18 |
class Block_Render extends Base { |
| 19 |
|
| 20 |
public function get_name() { |
| 21 |
return 'select-field'; |
| 22 |
} |
| 23 |
|
| 24 |
protected function set_checked_option( array &$option ) { |
| 25 |
$this->block_type->is_multiple() |
| 26 |
? $this->modify_option_from_array( $option ) |
| 27 |
: $this->modify_option_from_single( $option ); |
| 28 |
} |
| 29 |
|
| 30 |
protected function modify_option_from_array( array &$option ) { |
| 31 |
$value = $this->args['default']; |
| 32 |
|
| 33 |
if ( ! is_array( $value ) ) { |
| 34 |
return; |
| 35 |
} |
| 36 |
|
| 37 |
if ( in_array( (string) $option['value'], $value, true ) ) { |
| 38 |
$option['selected'] = true; |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
protected function modify_option_from_single( array &$option ) { |
| 43 |
if ( (string) $option['value'] === (string) $this->args['default'] ) { |
| 44 |
$option['selected'] = true; |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
} |
| 49 |
|