Checks $fields if specified, returns variation fields otherwise.

@param array $fields

@throws \RuntimeException

@return array
423163
protected function getMergedFields(array $fields)
    {
        if (0 === \count($fields)) {
            // If we didn't specify the fields (filtered), we get all variation fields possible values
            $fields = $this->getVariationFields();
        } else {
            foreach ($fields as $field) {
                if (!\in_array($field, $this->getVariationFields(), true)) {
                    throw new \RuntimeException("The field '".$field."' is not among the variation fields");
                }
            }
        }

        return $fields;
    }
265248
public function findSentinels(array $fields)
    {
        $timestamps = [];
        $deletes = [];
        $fields = $this->removeSentinel($fields, $timestamps, $deletes);

        return [$fields, $timestamps, $deletes];
    }
130638
public static function cleanFields($fields)
    {
        $fields = parent::cleanFields($fields);
        if (('*' !== array_get($fields, 0)) && !in_array('private', $fields)) {
            $fields[] = 'private';
        }

        return $fields;
    }
123525
public static function filter(array $fields)
    {
        if (array_values($fields) === $fields)
        {
            if (($key = array_search('id', $fields)) !== false)
            {
                unset($fields[$key]);
            }
        }
        else
        {
            unset($fields['id']);
        }
        return $fields;
    }
824192
public function getXMLValues($fields)
    {
        $result = [];

        foreach ($fields as $field) {
            $result[$field] = $this->XML_val($field);
        }

        return $result;
    }
492762
protected function getFormPlaceholders(array $fields)
    {
        $attributes = [];

        foreach ($fields as $field) {
            /** @var FieldTypeInterface $field */
            $attributes[$field->getName()] = $field->getOption('placeholder');
        }

        return $attributes;
    }
1057696
protected function getFieldsToDisplay(array $fields = null)
    {
        if (!empty($fields)) {
            return array_filter($this->fields, function ($field) use ($fields) {
                return in_array($field->name, $fields);
            });
        }

        return $this->fields;
    }
177535
final public function toArrayFor($fields){
		$array = array();
		$all = $this->toArray();
		foreach($fields as $field){
			if( array_key_exists($field, $all) ){
				$array[$field] = $all[$field];
			}
		}
		return $array;
	}
428052
public function fields($fields)
    {
        if (!is_array($fields)) {
            $fields = func_get_args();
        }

        $this->fields = array_merge($this->fields, $fields);

        return $this;
    }
544018
public static function fields($fields) {

        $arr = array();
        if ( is_string($fields) ) {
            $fields = explode(',', $fields);
        }
        foreach ( $fields as $key => $value ) {
            $arr[trim($value)] = 1;
        }
        return $arr;
    }
1011485
public function fields(array $fields)
    {
        $fields = self::filter($fields);
        $diff   = array_diff($fields, Config::table($this->name)->fields());

        if (empty($diff))
        {
            return true;
        }
        throw new dbException('Field(s) "' . implode(', ', $diff) . '" does not exists in table "' . $this->name . '"');
    }
1068554
protected function constructFieldMeta(array $fields)
    {
        $result = array();
        foreach ($fields as $key => $field) {
            $name = isset($field['name']) ? $field['name'] : (isset($field['id']) ? $field['id'] : $key);
            $type = $field['type'];
            if ($type === 'checkbox') {
                foreach ($field['options'] as $checkboxKey => $option) {
                    $data = new \stdClass();
                    $data->name = $name;
                    $data->type = $type;
                    $data->collection = $key;
                    $result[$checkboxKey] = $data;
                }
            } else {
                $data = new \stdClass();
                $data->name = $name;
                $data->type = $type;
                $result[$key] = $data;
            }

            if (!empty($field['fields'])) {
                $result += $this->constructFieldMeta($field['fields']);
            }
        }
        return $result;
    }
184532
private function cleanFields(array $fields): array
    {
        foreach ($fields['fields'] as &$field) {
            if (array_key_exists('generator', $field[key($field)])) {
                unset($field[key($field)]['generator']);
            }
        }

        unset($fields['section']);
        return $fields;
    }
324836
protected function buildAllFields(array $fields) : array
    {
        foreach ($fields as $key => $field) {
            if ($field instanceof FieldBuilderBase) {
                $fields[$key] = $field->build();
            }
        }

        return $fields;
    }
657893
protected function getPrimaryField(array $fields)
    {
        foreach ($fields as $field) {
            if ($this->isField($field) && ($field->isPrimary || $field->isAutoIncrement)) {
                return $field;
            }
        }

        return null;
    }
846180
public function addMetaField(array $fields)
    {
        $this->setMeta($this->constructFieldMeta($fields));
        $fields[static::Meta] = array(
            'type' => 'hidden',
            'value' => json_encode($this->getMeta()),
        );
        return $fields;
    }
113602
public function fields($fields) {
        if (!is_array($fields)) {
            $fields = func_get_args();
        }

        $this->_fields = $fields;

        return $this;
    }