Hi!
I’m making a plugin to generate my OG images, adapted from @rasteiner’s (very helpful) code from this message: OpenGraph image generation when page is edited, not when image url is requested - #2 by rasteiner.
I’ve noticed that when defining a Page Method in a plugin, and then checking if the method exists for the page in a hook defined in the same plugin, the method_exists
check returnss false
.
See code:
Kirby::plugin('joachim/opengraph-images', [
'pageMethods' => [
//Generate the OpenGraph image
'createOgImage' => function () {
…
},
],
'hooks' => [
'page.update:after' => function (Kirby\Cms\Page $newPage) {
// if the page has a createOgImage() method, call it.
if(method_exists($newPage, 'createOgImage')) {
$newPage->createOgImage();
}
},
],
]);
On the other hand, when removing the check, the method is exectuted when the hook fires, so it seems to exist after all?
Instead of using this check I ended up using a null safe operator, like this: $newPage?->createOgImage();
Anyways, I don’t know if it a bug or a bad understanding of how things should work, but I thought it could help to document it
Have a great day!
—
Joachim