1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
<?php
abstract class CMB2_Type_Multi_Base extends CMB2_Type_Base {
public function select_option( $args = array() ) {
return sprintf( "\t" . '<option value="%s" %s>%s</option>', $args['value'], selected( isset( $args['checked'] ) && $args['checked'], true, false ), $args['label'] ) . "\n";
}
public function list_input( $args = array(), $i = '' ) {
$a = $this->parse_args( 'list_input', array(
'type' => 'radio',
'class' => 'cmb2-option',
'name' => $this->_name(),
'id' => $this->_id( $i ),
'value' => $this->field->escaped_value(),
'label' => '',
), $args );
return sprintf( "\t" . '<li><input%s/> <label for="%s">%s</label></li>' . "\n", $this->concat_attrs( $a, array( 'label' ) ), $a['id'], $a['label'] );
}
public function list_input_checkbox( $args, $i ) {
$saved_value = $this->field->escaped_value();
if ( is_array( $saved_value ) && in_array( $args['value'], $saved_value ) ) {
$args['checked'] = 'checked';
}
$args['type'] = 'checkbox';
return $this->list_input( $args, $i );
}
public function concat_items( $args = array() ) {
$field = $this->field;
$method = isset( $args['method'] ) ? $args['method'] : 'select_option';
unset( $args['method'] );
$value = null !== $field->escaped_value()
? $field->escaped_value()
: $field->get_default();
$value = CMB2_Utils::normalize_if_numeric( $value );
$concatenated_items = '';
$i = 1;
$options = array();
if ( $option_none = $field->args( 'show_option_none' ) ) {
$options[''] = $option_none;
}
$options = $options + (array) $field->options();
foreach ( $options as $opt_value => $opt_label ) {
$a = $args;
$a['value'] = $opt_value;
$a['label'] = $opt_label;
if ( $value === CMB2_Utils::normalize_if_numeric( $opt_value ) ) {
$a['checked'] = 'checked';
}
$concatenated_items .= $this->$method( $a, $i++ );
}
return $concatenated_items;
}
}