public static function getFormFields($model, $fields, $multiple = false, $hiddenAttributes = [])
    {
        if (!$model instanceof \yii\db\ActiveRecord) {
            return $model->safeAttributes();
        }

        $keys = Action::getModelKeys($model);
        $hiddenAttributes = array_flip($hiddenAttributes);

        list($behaviorAttributes, $blameableAttributes) = Action::getModelBehaviorAttributes($model);
        $attributes = $model->safeAttributes();
        $relations = $model->relations();
        if (($versionAttribute = $model->optimisticLock()) !== null) {
            $hiddenAttributes[$versionAttribute] = true;
        }

        $formFields = [];
        foreach ($fields as $key => $field) {
            if ($field instanceof ActiveField) {
                $formFields[$key] = $field;
                continue;
            } elseif (!is_string($field) && is_callable($field)) {
                $formFields[$key] = call_user_func($field, $model);
                if (!is_string($formFields[$key])) {
                    throw new InvalidConfigException('Field definition must be either an ActiveField or a callable.');
                }
                continue;
            } elseif (!is_string($field)) {
                throw new InvalidConfigException('Field definition must be either an ActiveField or a callable.');
            }
            $attributeName = Html::getAttributeName($field);

            if (in_array($attributeName, $relations)) {
                $formFields = static::addRelationField(
                    $formFields, $model, $field,
                    $hiddenAttributes, $attributes, $multiple
                );
            } elseif (in_array($attributeName, $attributes)) {
                if (in_array($attributeName, $keys) || (in_array($attributeName, $behaviorAttributes))) {
                    continue;
                }
                $formFields = static::addFormField(
                    $formFields, $model, $field,
                    $hiddenAttributes, $multiple
                );
            }
        }

        return $formFields;
    }