Finds a field's options given a field name and a type (filter/edit).

@param string $field
@param string $type

@return mixed
199686
public function getFieldObjectByName($field, $type)
    {
        $info = false;

        //we want to get the correct options depending on the type of field it is
        if ($type === 'filter') {
            $fields = $this->getFilters();
        } else {
            $fields = $this->getEditFields();
        }

        //iterate over the fields to get the one for this $field value
        foreach ($fields as $key => $val) {
            if ($key === $field) {
                $info = $val;
            }
        }

        return $info;
    }
742071
private function getJqFilterField($field)
    {
        if (!isset($this->jqFilterFields) || !is_array($this->jqFilterFields)) {
            $this->jqFilterFields = $this->jqSearchable;
        }

        if (!isset($this->jqFilterFields) || !is_array($this->jqFilterFields)) {
            return $field;
        }

        return isset($this->jqFilterFields[$field]) ? $this->jqFilterFields[$field] : $field;
    }
1343099
public function orderBy(string $field, string $type=''): QueryBuilderInterface
	{
		// When ordering by random, do an ascending order if the driver
		// doesn't support random ordering
		if (stripos($type, 'rand') !== FALSE)
		{
			$rand = $this->driver->getSql()->random();
			$type = $rand ?? 'ASC';
		}

		// Set fields for later manipulation
		$field = $this->driver->quoteIdent($field);
		$this->state->setOrderArray($field, $type);

		$orderClauses = [];

		// Flatten key/val pairs into an array of space-separated pairs
		foreach($this->state->getOrderArray() as $k => $v)
		{
			$orderClauses[] = $k . ' ' . strtoupper($v);
		}

		// Set the final string
		$orderString =  ! isset($rand)
			? "\nORDER BY ".implode(', ', $orderClauses)
			: "\nORDER BY".$rand;

		$this->state->setOrderString($orderString);

		return $this;
	}
36182
public function fetchField($field=null, $options=null)
    {
        $this->getQuery()->type('select');
        if ($options) {
            $this->getQuery()->set(static::formatQueryOptions($options));
        }
        if ($field) {
            $this->getQuery()->remove('fields')->set('fields', $field);
        }
        $fields = StringHelper::explode(',', $this->getQuery()['fields']);
        $fields = array_map(function ($v) {
            $vs = preg_split('/(as)?\s+/', trim($v));
            return $vs[count($vs)-1];
        }, $fields);
        
        $rows = $this->query();
        
        $result = [];
        if ($rows) foreach ($rows as $v) {
            $result[] = $v[$fields[0]];
        }
        return $result;
    }
444282
public function getUploadFieldOptions($field = null)
    {
        // get first option if no field provided
        if (is_null($field)) {
            $imagesFields = $this->getDefinedUploadFields();

            if (!$imagesFields) {
                throw new InvalidUploadFieldException(
                    'No upload fields are defined in $imageFields/$fileFields array on model.'
                );
            }

            $fieldKey = array_first(array_keys($imagesFields));
            $options = is_int($fieldKey) ? [] : array_first($imagesFields);

            return $options;
        }

        // check if provided filed defined
        if (!$this->hasImageField($field)) {
            throw new InvalidUploadFieldException(
                'Image/File field `' . $field . '` is not defined in $imageFields/$fileFields array on model.'
            );
        }

        return array_get($this->getDefinedUploadFields(), $field, []);
    }
1256575
public function getOptions(array $fields = [])
    {
        if (!empty($fields)) {
            return \array_filter(\array_intersect_key($this->getParams(), \array_flip($fields)));
        }

        return \array_filter($this->getParams());
    }
1136254
public function getFieldType($field)
    {
        // default form field type
        $type = 'Line';

        // try to find associated form field type
        if (isset($this->type_associations[$field->type()])) {
            $type = $this->type_associations[$field->type()];
        }
        if ($field instanceof Field_Reference) {
            $type = 'DropDown';
        }

        // if form field type explicitly set in model
        if ($field->display()) {
            $tmp = $field->display();
            if (is_array($tmp)) {
                $tmp = $tmp['form'];
            }
            if ($tmp) {
                $type = $tmp;
            }
        }

        return $type;
    }
495550
public function serialize(Field $field, array $options = [])
    {
        $serialized = [
            'id' => $field->getUuid(),
            'autoId' => $field->getId(),
            'name' => $field->getName(),
            'label' => $field->getName(),
            'type' => $field->getFieldType(),
            'required' => $field->isRequired(),
            'help' => $field->getHelp(),
            'restrictions' => [
                'isMetadata' => $field->getIsMetadata(),
                'locked' => $field->isLocked(),
                'lockedEditionOnly' => $field->getLockedEditionOnly(),
                'hidden' => $field->isHidden(),
                'order' => $field->getOrder(),
            ],
        ];

        if (count($field->getDetails()) > 0) {
            $serialized['options'] = $field->getDetails();
        }
        if (in_array($field->getType(), [FieldFacet::CHOICE_TYPE, FieldFacet::CASCADE_TYPE])) {
            $serialized['options']['choices'] = array_map(function (FieldFacetChoice $choice) {
                return $this->fieldFacetChoiceSerializer->serialize($choice);
            }, $field->getFieldFacet()->getRootFieldFacetChoices());
        }
        if (!in_array(Options::SERIALIZE_MINIMAL, $options)) {
            $serialized = array_merge($serialized, [
                'fieldFacet' => $this->fieldFacetSerializer->serialize($field->getFieldFacet()),
            ]);
        } else {
            $serialized = array_merge($serialized, [
                'fieldFacet' => [
                    'id' => $field->getUuid(),
                ],
            ]);
        }

        return $serialized;
    }
1239546
protected function getFieldOptionsArray(FieldInterface $field)
    {
        $choices = [];
        $fieldOptions = $this->getFieldOptions($field);
        if (isset($fieldOptions['choices']) && is_array($fieldOptions['choices'])) {
            $choices = $fieldOptions['choices'];
        }
        return $choices;
    }
1263346
public function option($option, $field = NULL) 
	{
		$group = [];
		$option['value'] = isset($option['value']) && $option['value'] ? $option['value'] : '';
		if ($field) {
			foreach ($field as $t) {
				if ($t['fieldtype'] == 'Group') {
					$t['setting'] = hst_str2array($t['setting']);
					if (preg_match_all('/\{(.+)\}/U', $t['setting']['option']['value'], $value)) {
						foreach ($value[1] as $v) {
							$group[] = $v;
						}
					}
				}
			}
			$_field = [];
			$_field[] = '<option value=""> -- </option>';
			foreach ($field as $t) {
				if ($t['fieldtype'] != 'Group' && !@in_array($t['fieldname'], $group)) {
					$_field[] = '<option value="'.$t['fieldname'].'">'.$t['name'].'</option>';
				}
			}
			$_field = @implode('', @array_unique($_field));
		}
		return '
			<div class="hstui-form-group hstui-form-group-sm">
	          <label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::fields.group.field').'</label>
	          <div class="hstui-u-sm-10 hstui-form-input">
	            <select class="hstui-input hstui-select" name="xx" id="fxx" >'.$_field.'</select>
	            <div class="hstui-form-input-tips" id="J_form_tips_name">'.hst_lang('hstcms::fields.group.field.tips').'</div>
	          </div>
	        </div>
			<div class="hstui-form-group hstui-form-group-sm">
	          <label class="hstui-u-sm-2 hstui-form-label">'.hst_lang('hstcms::fields.group.rule').'</label>
	          <div class="hstui-u-sm-10 hstui-form-input">
	            <textarea name="setting[option][value]" id="fvalue" style="width:520px;height:120px;" class="hstui-input hstui-textarea">'.$option['value'].'</textarea>
	            <div class="hstui-form-input-tips" id="J_form_tips_name" data-tips="'.hst_lang('hstcms::fields.group.rule.tips').'">'.hst_lang('hstcms::fields.group.rule.tips').'</div>
	          </div>
	        </div>
				<script type="text/javascript">
				Hstui.use(\'jquery\',function() {
					$("#fxx").change(function(){
						var value = $(this).val();
						var fvalue = $("#fvalue").val();
						var text = $("#fxx").find("option:selected").text();
						$("#fxx option[value=\'"+value+"\']").remove();
						$("#fvalue").val(fvalue+" "+text+": {"+value+"}");
					});
				});
				</script>';
	}
472686
final public function getRowFieldValue($field)
    {

        //If value exists;
        if (array_key_exists($field, $this->schema)) {
            return $this->schema[$field]->Value;
        }
        return null;
    }
335761
public function hasFilter(string $field): bool
    {
        foreach ($this->filters as $filter) {
            if ($filter->hasFilter($field)) {
                return true;
            }
        }

        return false;
    }
1229705
protected function setDataType(Field & $field, $type)
    {
        $map = $this->dataTypeMap();

        if (array_key_exists($type, $map)) {
            $field->dataType = $map[$type];
        }

        return $this;
    }
1016704
public function getName($name, $field = null, $type = null)
    {
        return implode('_', array_filter(array($type, $field, $name)));
    }
639435
public function getField($field)
    {
        if (isset($this->allFields[$field])) {
            return $this->allFields[$field];
        }

        return null;
    }
967307
public function getFormFieldValueOptions(FieldInterface $field)
    {
        $formFieldOptions = [];
        $formFieldOptions['choices'] = array_flip($this->getFieldOptionsArray($field));
        $formFieldOptions['expanded'] = $this->isExpanded;
        $formFieldOptions['multiple'] = $this->getIsMultipleChoice($field);

        return $formFieldOptions;
    }
919006
public static function factoryType($field)
    {
        $data = [];
        $persistence = new Persistence_Array($data);
        $filterDomain = 'atk4\\ui\\TableColumn\\FilterModel\Type';

        // check if field as a type and use string as default
        if (empty($type = $field->type)) {
            $type = 'string';
        }
        $class = $filterDomain.ucfirst($type);

        /*
         * You can set your own filter model condition by extending
         * Field class and setting your filter model class.
         */
        if (!empty($field->filterModel) && isset($field->filterModel)) {
            if ($field->filterModel instanceof Model) {
                return $field->filterModel;
            }
            $class = $field->filterModel;
        }

        return new $class($persistence, ['lookupField' => $field]);
    }