Automator_Helpers_Recipe_Field::select_field_args( $args )


Parameters Parameters

$args

(Required)


Top ↑

Return Return

(mixed|void)


Source Source

File: src/core/lib/helpers/class-automator-recipe-helpers-field.php

	public function select_field_args( $args ) {
		// Create the array that will contain the field elements
		$field_args = array(
			'input_type' => 'select',
		);

		// Check if the select has the required elements
		if ( isset( $args['option_code'], $args['options'] ) ) {
			// Add the option_code and options to the field $args
			$field_args['option_code'] = $args['option_code'];
			$field_args['options']     = $args['options'];

			// Required
			// default: false
			$field_args['required'] = isset( $args['required'] ) ? (boolean) $args['required'] : false;

			// Label
			if ( isset( $args['label'] ) ) {
				$field_args['label'] = $args['label'];
			}

			// Description
			if ( isset( $args['description'] ) ) {
				$field_args['description'] = $args['description'];
			}

			// Placeholder
			if ( isset( $args['placeholder'] ) ) {
				$field_args['placeholder'] = $args['placeholder'];
			}

			// Token name
			// Check if there is a token name defined, otherwise,
			// check if the field has a label defined, if so, use it, otherwise
			// use the field option code
			// default: label, or option_code
			$field_args['token_name'] = isset( $args['token_name'] ) ? $args['token_name'] : ( ! isset( $field_args['label'] ) ? $field_args['label'] : $field_args['option_code'] );

			// Default value
			if ( isset( $args['default_value'] ) ) {
				$field_args['default_value'] = $args['default_value'];
			}

			// Relevant tokens
			if ( isset( $args['relevant_tokens'] ) && is_array( $args['relevant_tokens'] ) ) {
				$field_args['relevant_tokens'] = $args['relevant_tokens'];
			}

			// Is AJAX
			// Check if "is_ajax" is defined, if it's true, and if "endpoint"
			// is defined, which is required when "is_ajax" is true
			if ( isset( $args['is_ajax'] ) && $args['is_ajax'] && isset( $args['endpoint'] ) ) {
				$field_args['is_ajax']  = true;
				$field_args['endpoint'] = $args['endpoint'];

				// "target_field"
				if ( isset( $args['target_field'] ) ) {
					$field_args['fill_values_in'] = $args['target_field'];
				}

				// "fill_values_in"
				// Check if the element is defined. This parameter is optional, but
				// only relevant if is_ajax is true.
				if ( isset( $args['fill_values_in'] ) ) {
					$field_args['endpoint'] = $args['fill_values_in'];
				}
			}

			// Supports multiple values
			// default: false
			$field_args['placeholder'] = isset( $args['placeholder'] ) ? $args['placeholder'] : '';

			// Supports multiple values
			// default: false
			$field_args['supports_multiple_values'] = isset( $args['supports_multiple_values'] ) ? $args['supports_multiple_values'] : false;

			// Supports custom value
			// default: true
			$field_args['supports_custom_value'] = isset( $args['supports_custom_value'] ) ? $args['supports_custom_value'] : true;

			// Elements related to supports custom value
			// First we have to check if it supports custom values
			if ( $field_args['supports_custom_value'] ) {
				// Supports tokens
				// default: true
				$field_args['supports_tokens'] = isset( $args['supports_tokens'] ) ? $args['supports_tokens'] : true;

				// Custom value description
				// default: ''
				$field_args['custom_value_description'] = isset( $args['custom_value_description'] ) ? $args['custom_value_description'] : true;
			}
		}

		$field_args = apply_filters_deprecated( 'uap_option_select_field_args', array( $field_args ), '3.0', 'automator_option_select_field_args' );

		return apply_filters( 'automator_option_select_field_args', $field_args );
	}