Automator_Utilities::keep_order_of_options( $item )
Convert options array (for selects) from associative array to array of associative arrays We need this to keep the order of the options in the JS
Contents
Parameters Parameters
- $item
-
(Required)
Return Return
(Uncanny_Automator$item;)
Source Source
File: src/core/lib/utilities/class-automator-utilities.php
public function keep_order_of_options( $item ) { // Check if it has options if ( isset( $item['options'] ) ) { // Iterate each option foreach ( $item['options'] as $option_key => $option ) { // Check if it's a select and has options in the select if ( in_array( $option['input_type'], array( 'select', 'radio' ), true ) && ( isset( $option['options'] ) && ! empty( $option['options'] ) ) ) { // Create array that will be used to create the new array of options $select_options = array(); // Iterate each option foreach ( $option['options'] as $select_option_value => $select_option_text ) { $select_options[] = array( 'value' => $select_option_value, 'text' => $select_option_text, ); } // Replace old array for new one $item['options'][ $option_key ]['options'] = $select_options; } } } // Check if it has group of options if ( isset( $item['options_group'] ) ) { // Iterate each group of options foreach ( $item['options_group'] as $option_key => $fields ) { // Iterate each option inside a group of options foreach ( $fields as $field_index => $option ) { // Check if it's a select and has options in the select if ( in_array( $option['input_type'], array( 'select', 'radio' ), true ) && isset( $option['options'] ) ) { // Create array that will be used to create the new array of options $select_options = array(); // Iterate each option foreach ( $option['options'] as $select_option_value => $select_option_text ) { $select_options[] = array( 'value' => $select_option_value, 'text' => $select_option_text, ); } // Replace old array for new one $item['options_group'][ $option_key ][ $field_index ]['options'] = $select_options; } } } } return $item; }
Expand full source code Collapse full source code View on Github