';
if ( $this->prefix ) {
echo '' . $this->prefix . '';
}
// The saved or default value:
$id = $this->get_option();
if ( ( $id == '' || $args["for_bank"] == true ) && ( isset( $this->default ) ) ) {
$id = $this->default;
}
echo '';
if ( $this->suffix ) {
echo '' . $this->suffix . '';
}
echo '';
// If called from the front end, needs to enqueue some extra files
if ( !is_admin() ) {
if ( !wp_script_is( 'select2' ) ) {
wp_enqueue_script( 'tpl-select2', tpl_base_uri() . '/framework/lib/select2/js/select2.min.js', array( 'jquery' ) );
}
wp_enqueue_style( 'tpl-select2-style', tpl_base_uri() . '/framework/lib/select2/css/select2.min.css', array() );
wp_enqueue_style( 'tpl-common-style', tpl_base_uri() . '/framework/style/common.css', array(), false );
}
}
// Container end of the form field
public function form_field_after ( $args ) {
$path_i = $this->get_level() * 2 + 1;
if ( !empty( $this->default ) && $args["show_default"] == true ) {
echo '
(';
echo __( 'default:', 'tpl' ) . ' ' . tpl_kses( $this->format_option( $this->default, array( "key" => false ) ) );
echo ')
';
}
echo ''; // .tpl-field-inner
if ( $this->repeat !== false ) {
$this->path[$path_i]++;
}
echo '';
}
// Formats the option into value
public function format_option ( $id, $args = array() ) {
// Deciding to return the key or the value
if ( !isset( $args["key"] ) ) {
$key = $this->key;
}
else {
$key = $args["key"];
}
$values = $this->values;
foreach ( $values as $k => $value ) {
if ( is_array( $value ) ) {
foreach ( $value as $sub_key => $sub_value ) {
$values[$sub_key] = $sub_value;
}
unset( $values[$k] );
}
}
if ( $key ) {
return $id;
}
elseif ( !isset( $values[$id] ) ) {
return $id;
}
else {
return $this->prefix . $values[$id] . $this->suffix;
}
}
// Gets the options in Gutenberg SelectControl format
public function gutenberg_values() {
$gutenberg_values = array();
foreach ( $this->values as $key => $value ) {
$gutenberg_values[] = array(
"value" => $key,
"label" => $value,
);
}
return $gutenberg_values;
}
}