spicywebau / craft-fieldlabels

Override Craft CMS field labels and instructions in the field layout designer
MIT License
123 stars 9 forks source link

getIsGuest() conditional returns true when signed into control panel #17

Closed aaronbushnell closed 5 years ago

aaronbushnell commented 5 years ago

Description

I think this is likely a race condition, but I'm not seeing the Relabel dropdowns or instructions when I'm signed in as a super admin. It looked like the JS wasn't even being included so I dug into this a bit deeper.

The conditional in Plugin.php for !$userSession->getIsGuest() returned false for me (indicating that I'm a guest) even though I'm signed in.

If I change this:

$this->_includeResources();
$this->_bindEvent();

to this:

Event::on(
    UrlManager::class,
    UrlManager::EVENT_REGISTER_CP_URL_RULES,
    function (RegisterUrlRulesEvent $event) {
        $this->_includeResources();
        $this->_bindEvent();
    }
);

And include the correct modules:

use craft\web\UrlManager;
use craft\events\RegisterUrlRulesEvent;

Everything works as expected.

I'm thinking Craft might be indicating that I'm a guest at some point in execution and then determines I'm signed in later?

I have devMode enabled so maybe this is influencing that path, too.

Other information