Page model function 'metadata' not working
CHE1RON opened this issue · comments
Hey there,
this line will always return false
even if such method exists, since custom page methods don't exist on the $page
object. Problem is line 32:
// Get metadata from page, if possible
if (method_exists($this->page, 'metadata') === true) { # << will always be false
$this->metadata = $this->page->metadata($languageCode);
}
Because of this, $page->metadata
is not populated, hence our check on line 86 never succeeds, rendering custom page method 'metadata' useless 😭 If a page method does not exist, Kirby assumes it's a Field
with value null
😕
Solution:
hasMethod
to the rescue:
// Get metadata from page, if possible
if ($this->page->hasMethod('metadata') === true) { # << njom njom
$this->metadata = $this->page->metadata($languageCode);
}
Voila! PR welcome, I guess? 🤣
There it is!
offtopic:
I'd like to see a new (patch) release after this getting merged, so I can further hack on your stuff in production 😆
Thanks @fabianmichael for your feedback, I totally forgot about this - but my approach should work in both situations (= no need for both checks), or am I mistaken ❓
@CHE1RON I’ve digged through Kirby’s source and it seems like the HasMethods
trait only searches Kirby’s built-in methods.
Alright, thanks for letting me know. If I can lend a hand, let me know, Discord or otherwise.