Description
Return the value(s) for the select fieldThe select field may be #optional indicating that no value is needed. The field may also be #multiple, indicating that a comma separated list should be returned. We need to be able to cater for this.
[0] => _oik_api_type [1] => Array ( ) [2] => Array ( [#field_type] => select [#title] => API type [#args] => Array ( [#options] => Array ( [shortcode] => shortcode [filter] => filter [action] => action [public] => public [private] => private [undefined] => undefined [deprecated] => deprecated [hook] => hook ) [#optional] => 1 ) )
Usage
$string = bw_return_field_select( $key, $value, $field );Parameters
- $key
- ( string ) required – the field name
- $value
- ( mixed ) required – the field value as array index 0, OR a string, or multiple array items
- $field
- ( array ) required – key value pairs containing the #options for the select field within the #args element
Returns
string the field value(s), comma separated as necessarySource
File name: oik-fields/includes/oik-fields.incLines:
1 to 27 of 27
function bw_return_field_select( $key, $value, $field ) { //bw_trace2(); //bw_backtrace(); $args = bw_array_get( $field, '#args', null ); $multiple = false; $select = array(); $result = null; if ( $args ) { $select = bw_array_get( $args, '#options', null ); $select = bw_as_array( $select ); $multiple = bw_array_get( $args, "#multiple", false ); } if ( $multiple ) { $results = array(); foreach ( $value as $val ) { $results[] = bw_array_get( $select, $val, $val ); } $result = implode( ", ", $results ); } else { // If value is an empty array this will return an empty array. $val = bw_array_get( $value, 0, $value ); if ( !empty( $val ) ) { $result = bw_array_get( $select, $val, $val ); } } return( $result ); }View on GitHub
Invoked by
Calls
1 to 2 of 2
