Skip to content

Instantly share code, notes, and snippets.

@dlubitz
Last active May 24, 2024 08:56
Show Gist options
  • Save dlubitz/778d06bd982e9db0f2174f3884ba9471 to your computer and use it in GitHub Desktop.
Save dlubitz/778d06bd982e9db0f2174f3884ba9471 to your computer and use it in GitHub Desktop.
Eel Helper to get the username of the currently logged in user
prototype(...) {
userName = ${VIVOMEDIA.FrontendLoginUser.getParty().name}
}
<?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