Closed LeBenLeBen closed 4 years ago
I can't reproduce this issue on 3.3.2 Starterkit. Could it be from plugins or hooks that wrong syntax?
I haven't tested with Markdown field but can't reproduce this either. I don't think it has anything to do with the model and I've been using many page models in 3.3.2 without any issues.
Indeed, the problem was coming from a page hook that was defined as function(Page $page) { … }
. Changing it for function($page) { … }
fixed the issue.
Sorry for the noise and thanks for the help!
@LeBenLeBen We struggled with that issue ourselves: PHP in its current versions doesn't treat type hinting with objects very well. It doesn't matches withdecendants but only the exact class. We removed all our object type hints for this reason.
@distantnative That's only the case for return types though (which was fixed in PHP 7.4, so we'll only need to wait a few more years until we can use that... :D).
Param type hints should actually work as your ExpertisePage
is also a Page
object and should therefore be supported by that Page
type hint.
The only issue that comes to my mind is that the internal class alias of Kirby\Cms\Page
to Page
may cause issues. @LeBenLeBen Do you have the use Kirby\Cms\Page
line also in the file where the hook is defined?
No use Kirby\Cms\Page
was not present in the file with the hook. I'm in the process of explicitely defining the use
everywhere.
I tried with following type hints as ExpertisePage
and Page
, works properly. It should work anyway like @lukasbestle said.
'page.update:before' => function (ExpertisePage $page, $values, $strings) {
// your code goes here
}
'page.update:before' => function (Page $page, $values, $strings) {
// your code goes here
}
I think there is an incorrect ExpertisePage
model file in the site or plugin models 🤔
I have been able to reproduce the original issue with a missing use
statement. Once I added it, the same code worked just fine. Seems to be a bug in PHP that makes aliases not work for type hinting.
Describe the bug
When I try to save a page in the panel that uses a custom Model, the following error is thrown:
To Reproduce
Here's my page blueprint (expertise.yml):
Model (expertise.php):
Expected behavior
I should be able to save the page like any other.
Kirby Version
3.3.2