tobimori / kirby-seo

🔎 All-in-one toolkit that makes implementing SEO & Meta best practices in your Kirby 4+ site a breeze

Home Page:https://plugins.andkindness.com/seo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Call to a member function metadata() on null

wdebusschere opened this issue · comments

I added seo/page to the page blueprint (also added the seo/site to the site blueprint), and it gives the error Call to a member function metadata() on null. the element with the error:

<div class="k-field k-info-field" form-data="[object Object]" name="robots" signature="f4ec69e10a563a018e3f8047a2b187f7" strict="true" type="info" width="1/1" section="seo-col-main-fields" endpoints="[object Object]"><h2 class="k-headline">Error</h2><div data-align="start" data-theme="negative" class="k-box"><!----><div class="k-text"><p>Call to a member function metadata() on null</p></div></div><!----></div>

Screenshot 2024-01-30 at 09 32 52

Are you on 1.0.0-rc.1?

"tobimori/kirby-seo": "1.0.0-rc.1"

Interesting, I had the same error and fixed it in rc.1 - but it seems I didn't catch all edge cases.

Why this error happens:
The robots blueprint is a dynamic blueprint that reads the request path (e.g. panel/pages/page+subpage+etc/some-subroute) and tries to find the page based on the middle part so it can correctly show the placeholder/fallback.
This error happens when it is unable to find a page.

In rc.1, I fixed that draft pages could also be found.

Is there anything special about this page or your environment that might lead to this issue? Can you share the request URLs from the network tab?

$kirby->request()->path()->data()[2]
on my localhost environment i just access the panel:
http://localhost/domain.pt/public/panel/pages/clients?tab=seo

i assume it's related to running on a subfolder then, will check

Hi, Tobias. Any update on this issue? I'm getting the same problem with 1.0.0-rc.2 in a localhost installation and a public-facing UAT environment. Both of them run in subfolders.

Thanks.

I could not reproduce this so far with my setup, have to try something else

For what it's worth, I've still got a previous version of the plugin that was just called 1.0.0 – no 'rc' release reference. With that version, the Robots blueprint section worked OK within seo/page. But it wasn't generating a sitemap.

With 1.0.0-rc.2, the sitemap generation works but, because of the issue with the Robots section in the blueprint, it is empty.

I think it can easily be solved by just grabbing the last part of $kirby->request()->path()->data(), instead of using [2] we could do something like:

$pathParts = $kirby->request()->path()->data();
$path = end($pathParts);

Have you tested it? I had the assumption that Kirby fires multiple API requests sometimes (like lock, or section APIs, etc.) and then a subsequent request wouldn't work.

Hi, this should be fixed here: 36d0538

Would appreciate if this actually fixes your issue by testing the mainbranch before I release it! Thanks :)

@tobimori Yes, this works for me, great

Just released it as 1.0.0-rc.3 then.

This is actually not working when page uid has a dash in it.

$matches = Str::match($path, "/pages\/([a-zA-Z0-9+]+)\/?/m");

I would modify this line to:

$matches = Str::match($path, "/pages\/([a-zA-Z0-9-_+]+)\/?/m");

you're right, completely forgot that! thanks.

Hello tobimori,
I also get the message "Call to a member function metadata() on null" when I open a page for the first time with 1.0.0-rc.5. It is a subpage on the 3rd level.

Is the page you're trying to access a draft? It seems like there's a Kirby bug in that case.

No, it is not a draft page. It is a product page that already existed before the plugin was installed.

Is any page in the chain a draft? I can only reproduce it that way

getkirby/kirby#6339

No, no drafts in the path.

okay, let me know if you have anything else that might help in reproducing this error.

Sorry. That was my mistake. No more metadata() equal null.

Hello Tobias,
the error persists when a new subpage is created and it is still in draft form. The findPageOrDraft() function from robots.php does not return this page, which results in subsequent errors, as the defaults are then not set. Can you please try to reproduce this error?
The argument for findPageOrDraft() is 'test-module/xxx' after the replace. The page xxx is in draft. The page test-module is published. However, I cannot say exactly where the error is.

As said, this error is from Kirby core and I'll wait for a fix from them

Might be a good idea to remove the required property from the Robots directives part until the correction arrives from Kirby side? This makes the plugin quite annoying to use as drafts don't get the default value from parent. Is there any reason for these fields to be required?

You can disable the robots page settings using your config and the robots index will still follow the page status.

1.0.0 should fix the error.