1: <?php
2:
3: 4: 5: 6:
7: class Papi_Property_Radio extends Papi_Property {
8:
9: 10: 11: 12: 13: 14: 15: 16: 17: 18:
19: public function format_value( $value, $slug, $post_id ) {
20: return papi_cast_string_value( $value );
21: }
22:
23: 24: 25: 26: 27:
28: public function get_default_settings() {
29: return [
30: 'items' => [],
31: 'selected' => ''
32: ];
33: }
34:
35: 36: 37:
38: public function html() {
39: $settings = $this->get_settings();
40: $value = papi_cast_string_value( $this->get_value() );
41:
42:
43:
44: if ( ! papi_is_empty( $value ) ) {
45: $settings->selected = $value;
46: }
47:
48: foreach ( $settings->items as $key => $value ) {
49: $key = is_numeric( $key ) ? $value : $key;
50:
51: papi_render_html_tag( 'label', [
52: 'class' => 'light',
53: 'for' => $this->html_id( $key ),
54:
55: papi_render_html_tag( 'input', [
56: 'id' => $this->html_id( $key ),
57: 'name' => $this->html_name(),
58: 'type' => 'radio',
59: 'checked' => $value === $settings->selected ? 'checked' : null,
60: 'value' => $value
61: ] ),
62:
63: papi_convert_to_string( $key )
64: ] );
65:
66: papi_render_html_tag( 'br' );
67: }
68: }
69: }
70: