LLMS_Form_Field::prepare_options( array $raw )
Prepare the fields options.
Description Description
Allows options to be setup as an associative array of key/value pairs or an array of associative arrays each with a "label" and "key" property. The "key" property may be omitted, in which case the "label" will be duplicated as the option’s "value".
Parameters Parameters
- $raw
-
(array) (Required) Raw field data.
Return Return
(array)
Source Source
File: includes/forms/class-llms-form-field.php
protected function prepare_options( $raw ) { $prepared = array(); foreach ( $raw as $key => $val ) { if ( is_array( $val ) ) { // Option group. if ( isset( $val['options'] ) ) { $prepared[ $key ] = array( 'label' => isset( $val['label'] ) ? $val['label'] : $key, 'options' => $this->prepare_options( $val['options'] ), ); // From block editor options array. } elseif ( isset( $val['text'] ) ) { $item_key = isset( $val['key'] ) ? $val['key'] : $val['text']; $prepared[ $item_key ] = $val['text']; if ( isset( $val['default'] ) && llms_parse_bool( $val['default'] ) ) { if ( 'checkbox' === $this->settings['type'] ) { // Account for multiple defaults. $this->settings['default'] = is_array( $this->settings['default'] ) ? $this->settings['default'] : array(); $this->settings['default'][] = $item_key; } else { $this->settings['default'] = $item_key; } } } // Flat array of $key=>$val. } else { $prepared[ $key ] = $val; } } // Add a placeholder. if ( $this->settings['placeholder'] ) { $this->settings['default'] = ''; $prepared = array_merge( array( '' => $this->settings['placeholder'] ), $prepared ); } return $prepared; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
5.0.0 | Introduced. |