options() public static method

Setup options for a field and store them for later use
Since: 2.0
public static options ( $type, $options ) : array
$type
$options
return array
コード例 #1
0
/**
 * Pre-populate options for bound fields
 *
 * @since 1.0.0
 *
 * @param array $field Field config
 *
 * @return array Field config
 */
function pods_cf_populate_options($field)
{
    global $form;
    $processors = Caldera_Forms::get_processor_by_type('pods', $form);
    if (empty($processors)) {
        return $field;
    }
    foreach ($processors as $processor) {
        // is configured
        $fields = array();
        if (!empty($processor['config']['fields'])) {
            $fields = array_merge($fields, $processor['config']['fields']);
        }
        if (!empty($processor['config']['object_fields'])) {
            $fields = array_merge($fields, $processor['config']['object_fields']);
        }
        if ($bound_field = array_search($field['ID'], $fields)) {
            // now lets see if this is a pick field
            $pod = pods($processor['config']['pod'], null, false);
            $pod_field = $pod->fields($bound_field);
            if (!empty($pod_field['options']['required'])) {
                $field['required'] = 1;
            }
            if ($pod_field['type'] === 'pick') {
                $options = PodsForm::options($pod_field['type'], $pod_field);
                include_once PODS_DIR . 'classes/fields/pick.php';
                $fieldtype = new PodsField_Pick();
                $choices = $fieldtype->data($bound_field, null, $options, $pod);
                $field['config']['option'] = array();
                foreach ($choices as $choice_value => $choice_label) {
                    $field['config']['option'][] = array('value' => $choice_value, 'label' => $choice_label);
                }
            }
        }
    }
    return $field;
}