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

Dynamic page visibility throws a critical error #2889

Closed
MakaryGo opened this issue Jan 17, 2020 · 3 comments
Closed

Dynamic page visibility throws a critical error #2889

MakaryGo opened this issue Jan 17, 2020 · 3 comments
Assignees

Comments

@MakaryGo
Copy link

Grav Admin Login
v1.7.0-rc.3 v1.10.0-rc.3 v3.0.5

When dynamic_page_visibility: is set to true Grav throws a critical error:

grav.CRITICAL: Call to a member function header() on null

Full log included:
error.last.log

@MakaryGo
Copy link
Author

Still happens on Admin v1.10-rc.6 & Grav v1.7.0-rc.6

Any chance for this function to work in 1.7?
Log below.

public function pageVisibility(Event $e)
    {
        if ($this->config->get('plugins.login.dynamic_page_visibility')) {
            /** @var Pages $pages */
            $pages = $e['pages'];
            $user = $this->grav['user'];

            foreach ($pages->instances() as $page) {
                $header = $page->header();
                if (isset($header) && isset($header->access) && isset($header->login['visibility_requires_access']) && $header->login['visibility_requires_access'] === true) {
                    $config = $this->mergeConfig($page);
                    $access = $this->login->isUserAuthorizedForPage($user, $page, $config);
                    if ($access === false) {
                        $page->visible(false);
                    }
                }
            }
        }
    }

@mahagr
Copy link
Member

mahagr commented Mar 2, 2020

It looks like $pages->instances() returns null as some page. Look for a broken page.

@mahagr mahagr self-assigned this Mar 2, 2020
@mahagr mahagr transferred this issue from getgrav/grav-plugin-login Apr 23, 2020
@mahagr
Copy link
Member

mahagr commented Apr 23, 2020

@MakaryGo Could you test with latest Grav CI build if your issue is fixed? We're going to do release maybe tomorrow.

Thanks!

@mahagr mahagr added the fixed label Apr 23, 2020
@mahagr mahagr closed this as completed Jun 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants