Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call to a member function metadata() on null #66

Closed
wdebusschere opened this issue Jan 30, 2024 · 27 comments
Closed

Call to a member function metadata() on null #66

wdebusschere opened this issue Jan 30, 2024 · 27 comments
Labels
type: bug 🐛 Is a bug; fixes a bug
Milestone

Comments

@wdebusschere
Copy link

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

@tobimori
Copy link
Owner

Are you on 1.0.0-rc.1?

@tobimori tobimori added the type: bug 🐛 Is a bug; fixes a bug label Jan 30, 2024
@wdebusschere
Copy link
Author

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

@tobimori
Copy link
Owner

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?

@wdebusschere
Copy link
Author

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

@tobimori
Copy link
Owner

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

@brandsis
Copy link

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.

@tobimori
Copy link
Owner

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

@brandsis
Copy link

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.

@wdebusschere
Copy link
Author

wdebusschere commented Feb 12, 2024

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);

@tobimori
Copy link
Owner

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.

@tobimori tobimori added this to the 1.0.0 milestone Mar 3, 2024
@tobimori
Copy link
Owner

tobimori commented Mar 5, 2024

Hi, this should be fixed here: 36d0538

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

@wdebusschere
Copy link
Author

wdebusschere commented Mar 5, 2024

@tobimori Yes, this works for me, great

@tobimori
Copy link
Owner

tobimori commented Mar 5, 2024

Just released it as 1.0.0-rc.3 then.

@tobimori tobimori closed this as completed Mar 5, 2024
@quentin-f451
Copy link

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");

@tobimori
Copy link
Owner

tobimori commented Mar 7, 2024

you're right, completely forgot that! thanks.

@LuckyRessource
Copy link

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.

@tobimori
Copy link
Owner

tobimori commented Mar 8, 2024

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

@LuckyRessource
Copy link

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

@tobimori
Copy link
Owner

tobimori commented Mar 8, 2024

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

getkirby/kirby#6339

@LuckyRessource
Copy link

No, no drafts in the path.

@tobimori
Copy link
Owner

tobimori commented Mar 8, 2024

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

@LuckyRessource
Copy link

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

@LuckyRessource
Copy link

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.

@tobimori
Copy link
Owner

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

@quentin-f451
Copy link

quentin-f451 commented Mar 13, 2024

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?

@tobimori
Copy link
Owner

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

@tobimori
Copy link
Owner

1.0.0 should fix the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐛 Is a bug; fixes a bug
Projects
None yet
Development

No branches or pull requests

5 participants