protected function flattenCollection($field)
    {
        if (!isset($field['fields']) || !is_array($field['fields'])) {
            return [];
        }

        $fields = [];

        foreach ($field['fields'] as $field) {
            if (isset($field['fields']) && is_array($field['fields'])) {
                $fields += $this->flattenCollection($field);
            } else {
                $fields[$field['name']] = $field;
            }
        }

        return $fields;
    }