After updating to Kirby 3.4.0: Call to a member function on null

Hi,

I just updated to Kirby 3.4.0 from 3.3.6 and getting this error when saving site.yml and other pages.

Any known changes that may cause this?

The only place where I have colorBackground() is in the config.php file inside a hook.

if ($site->colorBackground()->isNotEmpty()) {
  $css = 'body{background:#' . $site->colorBackground() . '}';
} else {
  $css = 'body{background:#fff}';
}

Do you still get the error if you comment out these lines in config.php?

And could you please post the complete hook?

Then it just moves to the next field.

Here’s the hook.

'hooks' => [
  'site.update:after' => function($site) {

    if ($site->colorBackground()->isNotEmpty()) {
      $css = 'body{background:#' . $site->colorBackground() . '}';
    } else {
      $css = 'body{background:#fff}';
    }

    F::write(kirby()->root('assets') . '/css/custom.min.css', $css);
  }
]

If I revert back to 3.3.6 it works.

The hook variables have changed, you now have to use the named variables, have you run the compatibility check?

Change $site to $newSite

How do I run the compatibility check?

So I need to replace $site everywhere I use it with $newSite?

Yes, you now have to use the variable names like in the hook documentation.

https://github.com/getkirby/kirby/releases/download/3.4.0/hook-migration-checker.zip

  • Kirby 3.4 hook migration checker plugin
  • Place this in site/plugins/migration/index.php
  • and visit any frontend page of your Kirby site
  • to check if you need to migrate some of your hooks.

Note that this doesn’t mean you have to change $site to $newSite everywhere in your code, just as the variable you pass to the hook, so

'hooks' => [
  'site.update:after' => function($newSite) {

    if ($newSite->colorBackground()->isNotEmpty()) {
      $css = 'body{background:#' . $newSite->colorBackground() . '}';
    } else {
      $css = 'body{background:#fff}';
    }

    F::write(kirby()->root('assets') . '/css/custom.min.css', $css);
  }
]
1 Like

Thanks! Working now, will check all the other pages with the plugin.