Updating to Kirby 4 from 3

I am trying to upgrade Kirby 3 to 4 but I got below errors which i am not sure how to fix.
I have been using objects that extend StructureObject in Kirby 3 like:
class TestStructureObject extends StructureObject

And then it was passed down and Model was expected in those function, but now I Am getting:
Kirby\Content\Field::__construct(): Argument #1 ($parent) must be of type ?Kirby\Cms\ModelWithContent, TestStructureObject given

And in the past StructureObject extended Model class, but it does not do that anymore, is there another class i should use right now? Is there an easy fix to that?

How should i use it?

We need to better understand where your TestStructureObject seems to get passed to Content\Field::__construct() as $parent. Do you have any insights on this yourself?

Hard to tell right now if it’s happening somewhere in the core code itself or if this is from custom code, e.g. in your TestStructureObject class itself.

It looks that object has page setting that is being read.

$TestStructureObject->formattedCompactPrice()->html()
Then it creates field in it at the end:
return new Field($this, ‘formattedCompactPrice’, $value);

$this is $TestStructureObjec t in this case.

This return creates that error.

I think you might be fine by changing it to

return new Field(null, ‘formattedCompactPrice’, $value);

The parent is mainly needed for $field->exists() and there for checking if it actually exists in the content. This is why we had to fix the type hinting and require ModelWithContent.

Assuming that your objects don’t need to make use of this, passing null should be fine.