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

Trying to access array offset on value of type null #78

Closed
Senexis opened this issue Apr 30, 2021 · 1 comment
Closed

Trying to access array offset on value of type null #78

Senexis opened this issue Apr 30, 2021 · 1 comment

Comments

@Senexis
Copy link

Senexis commented Apr 30, 2021

Hey there, great package!

I've been experimenting with the package and found that using nova_page_manager_get_page_by_path with a draft page throws the following when not providing a preview token (so basically a regular user):

[2021-04-30 09:42:08] local.ERROR: Trying to access array offset on value of type null
{"userId":1,"exception":"
[object] (ErrorException(code: 0): Trying to access array offset on value of type null at D:\\Projects\\[SNIP]\\vendor\\optimistdigital\\nova-page-manager\\src\\helpers.php:368)
[stacktrace]
#0 D:\\Projects\\[SNIP]\\vendor\\optimistdigital\\nova-page-manager\\src\\helpers.php(368): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()
#1 D:\\Projects\\[SNIP]\\app\\Http\\Controllers\\PageController.php(41): nova_page_manager_get_page_by_path()
[SNIP]
"} 

The page controller looks like the following:

public function show(string $path)
{
    $previewToken = request()->input('preview');
    $result = nova_page_manager_get_page_by_path($path, $previewToken, 'nl');

    // Snip for brevity, validates the existence of $result in addition to other things.

    // Return the view using data from $result.
    return View::first(["pages.{$result->template}", 'pages.fallback'], $data);
}

This seems to occur because $parent cannot be properly found in the nova_page_manager_get_page_by_path helper function. Please feel free to reach out if you need more information!

Instead of it crashing like this, I would expect it to abort with 404 if the page could not be found at all (for regular users so without preview tokens, a draft should not be found at all). Is there some logic beforehand I should be manually checking for? If so, please let me know and update the documentation as I could not find information regarding this specific case. Thanks!

Here's my composer json so you know what versions I'm using. As far as I'm aware, it's the latest versions:

"optimistdigital/nova-drafts": "^1.1",
"optimistdigital/nova-page-manager": "^3.5",

Cheers!

Tarpsvo added a commit that referenced this issue Jun 18, 2021
@Tarpsvo
Copy link
Collaborator

Tarpsvo commented Jun 18, 2021

Heya! I made a theoretical fix to it and released it in version 4.0.0. It should now return null and fall back to 404 as one would expect. Thanks!

@Tarpsvo Tarpsvo closed this as completed Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants