steirico / kirby-plugin-custom-add-fields

Custom fields for Kirby's add dialog.
MIT License
36 stars 4 forks source link

Error message when saving a draft #46

Closed MikeHarrison closed 3 years ago

MikeHarrison commented 3 years ago

Hi,

I have installed the plugin, and started working out how to use it to create custom slugs for my pages. I currently have this set in my template:

addFields:
  title:
    label: Title
    type: text
    required: true
    icon: title
  startDate:
    type: date
    label: Start date & time
    time: true
    required: true

And when I click to add a page the correct fields are appearing. However when I click Create Draft I am getting the following error message:

method_exists(): Argument #1 ($object_or_class) must be of type object|string, null given

The draft is created correctly, but something isn't working quite right. If you have any insight that would be great

steirico commented 3 years ago

Hi,

you state that you intent to create custom slugs. Therefore, I assume a problem in that area.

Did you follow the instructions in the README? Does the plugin work as expected without custom slugs? Could you provide the code of your hookPageCreate($page) method (c.f.)?

REHvision commented 3 years ago

The error seems to originate from line 159 in the config.php file:

$modelName = a::get(Page::$models, $page->intendedTemplate()->name());
nilshoerrmann commented 3 years ago

I just ran into this problem and it seems it is related to PHP versions: Everything is fine using PHP 7 but PHP 8 throws the above error.

The error occurs as soon as $modelName is null in line 161 of config.php: https://github.com/steirico/kirby-plugin-custom-add-fields/blob/ba08f4650a9a08dc15b79cf06deafb9a6e0166bb/config.php#L159-L163

Everything works fine again after adding a check if $modelName is set before checking for the methods' existence.