private function setRequired(array $fields, string $groupName = null): array
    {
        foreach ($fields as $fieldName => $field) {
            if (!empty($field['required'])) {
                if (isset($field['groups']) && !is_array($field['groups'])) {
                    $field['groups'] = [$field['groups']];
                }
                if (empty($field['groups']) || in_array($groupName, $field['groups'])) {
                    $fields[$fieldName] = $this->makeRequired($fields[$fieldName]);
                }
            }
        }

        return $fields;
    }