CMB2_Type_Multi_Base

CMB Multi base field type.

Defined (1)

The class is defined in the following location(s).

/vendor/wordimpress/maps-builder-core/includes/libraries/metabox/includes/types/CMB2_Type_Multi_Base.php  
  1. abstract class CMB2_Type_Multi_Base extends CMB2_Type_Base { 
  2.  
  3. /** 
  4. * Generates html for an option element 
  5. * @since 1.1.0 
  6. * @param array $args Arguments array containing value, label, and checked boolean 
  7. * @return string Generated option element html 
  8. */ 
  9. public function select_option( $args = array() ) { 
  10. return sprintf( "\t" . '<option value="%s" %s>%s</option>', $args['value'], selected( isset( $args['checked'] ) && $args['checked'], true, false ), $args['label'] ) . "\n"; 
  11.  
  12. /** 
  13. * Generates html for list item with input 
  14. * @since 1.1.0 
  15. * @param array $args Override arguments 
  16. * @param int $i Iterator value 
  17. * @return string Gnerated list item html 
  18. */ 
  19. public function list_input( $args = array(), $i ) { 
  20. $a = $this->parse_args( 'list_input', array( 
  21. 'type' => 'radio',  
  22. 'class' => 'cmb2-option',  
  23. 'name' => $this->_name(),  
  24. 'id' => $this->_id( $i ),  
  25. 'value' => $this->field->escaped_value(),  
  26. 'label' => '',  
  27. ), $args ); 
  28.  
  29. return sprintf( "\t" . '<li><input%s/> <label for="%s">%s</label></li>' . "\n", $this->concat_attrs( $a, array( 'label' ) ), $a['id'], $a['label'] ); 
  30.  
  31. /** 
  32. * Generates html for list item with checkbox input 
  33. * @since 1.1.0 
  34. * @param array $args Override arguments 
  35. * @param int $i Iterator value 
  36. * @return string Gnerated list item html 
  37. */ 
  38. public function list_input_checkbox( $args, $i ) { 
  39. $saved_value = $this->field->escaped_value(); 
  40. if ( is_array( $saved_value ) && in_array( $args['value'], $saved_value ) ) { 
  41. $args['checked'] = 'checked'; 
  42. $args['type'] = 'checkbox'; 
  43. return $this->list_input( $args, $i ); 
  44.  
  45. /** 
  46. * Generates html for concatenated items 
  47. * @since 1.1.0 
  48. * @param array $args Optional arguments 
  49. * @return string Concatenated html items 
  50. */ 
  51. public function concat_items( $args = array() ) { 
  52. $field = $this->field; 
  53.  
  54. $method = isset( $args['method'] ) ? $args['method'] : 'select_option'; 
  55. unset( $args['method'] ); 
  56.  
  57. $value = $field->escaped_value() 
  58. ? $field->escaped_value() 
  59. : $field->get_default(); 
  60.  
  61. $concatenated_items = ''; $i = 1; 
  62.  
  63. $options = array(); 
  64. if ( $option_none = $field->args( 'show_option_none' ) ) { 
  65. $options[ '' ] = $option_none; 
  66. $options = $options + (array) $field->options(); 
  67. foreach ( $options as $opt_value => $opt_label ) { 
  68.  
  69. // Clone args & modify for just this item 
  70. $a = $args; 
  71.  
  72. $a['value'] = $opt_value; 
  73. $a['label'] = $opt_label; 
  74.  
  75. // Check if this option is the value of the input 
  76. if ( $value == $opt_value ) { 
  77. $a['checked'] = 'checked'; 
  78.  
  79. $concatenated_items .= $this->$method( $a, $i++ ); 
  80.  
  81. return $concatenated_items; 
  82.