fabianmichael / kirby-meta

All-in-one solution to all of your SEO/OpenGraph/JSON-LD needs. 👀

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 😆

@CHE1RON Usually, metadata() is implemented on custom page models as a "real" method, so this was intentional. However, I added the possibility to use Kirby’s "virtual" methods as well, see 02f79b9.

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.