Last active
May 24, 2024 08:56
-
-
Save dlubitz/778d06bd982e9db0f2174f3884ba9471 to your computer and use it in GitHub Desktop.
Eel Helper to get the username of the currently logged in user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prototype(...) { | |
userName = ${VIVOMEDIA.FrontendLoginUser.getParty().name} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace VIVOMEDIA\FrontendLogin\Eel\Helper; | |
use Neos\Eel\ProtectedContextAwareInterface; | |
use Neos\Flow\Annotations as Flow; | |
use Neos\Flow\Security\Context; | |
use Neos\Party\Domain\Service\PartyService; | |
class UserHelper implements ProtectedContextAwareInterface { | |
/** | |
* @Flow\Inject | |
* @var Context | |
*/ | |
protected $securityContext; | |
/** | |
* @Flow\Inject | |
* @var PartyService | |
*/ | |
protected $partyService; | |
/** | |
* Get the Party | |
* | |
* @return null|\Neos\Party\Domain\Model\AbstractParty | |
*/ | |
public function getParty() { | |
if ($this->securityContext->canBeInitialized()) { | |
$account = $this->securityContext->getAccount(); | |
if($account) { | |
return $this->partyService->getAssignedPartyOfAccount($account); | |
} | |
} | |
return null; | |
} | |
/** | |
* @param string $methodName | |
* @return boolean | |
*/ | |
public function allowsCallOfMethod($methodName) | |
{ | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment