Skip to content

Instantly share code, notes, and snippets.

@nezaniel
Last active August 4, 2017 15:09
Show Gist options
  • Save nezaniel/a333b95bd06dfa3dc57ce3faacf8c655 to your computer and use it in GitHub Desktop.
Save nezaniel/a333b95bd06dfa3dc57ce3faacf8c655 to your computer and use it in GitHub Desktop.
Neos Backend Redirection aspect
/**
* The aspect for redirecting asset editors to the media management module
*
* @Flow\Scope("singleton")
* @Flow\Aspect
*/
class BackendRedirectionAspect
{
/**
* @Flow\Inject
* @var UserService
*/
protected $userService;
/**
* After returning advice
*
* @Flow\Around("method(public TYPO3\Neos\Service\BackendRedirectionService->getAfterLoginRedirectionUri())")
* @param JoinPointInterface $joinPoint
* @return string
*/
public function redirectAssetEditors(JoinPointInterface $joinPoint)
{
$backendUser = $this->userService->getBackendUser();
$roleIdentifiers = $this->getAllRoleIdentifiers($backendUser);
if (in_array('My.Site:AssetEditor', $roleIdentifiers)
&& !in_array('TYPO3.Neos:Editor', $roleIdentifiers)
) {
$uriBuilder = new UriBuilder();
$uriBuilder->setRequest($joinPoint->getMethodArgument('actionRequest'));
$uriBuilder->setFormat('html');
$uriBuilder->setCreateAbsoluteUri(true);
return $uriBuilder->uriFor('index', [
'module' => 'management/media',
'moduleArguments' => [
'@action' => 'index'
]
], 'Backend\\Module', 'TYPO3.Neos');
} else {
return $joinPoint->getAdviceChain()->proceed($joinPoint);
}
}
/**
* @param User $backendUser
* @return array
*/
protected function getAllRoleIdentifiers(User $backendUser)
{
$roleIdentifiers = [];
foreach ($backendUser->getAccounts() as $account) {
/** @var Account $account */
foreach ($account->getRoles() as $role) {
/** @var Role $role */
$roleIdentifiers[] = $role->getIdentifier();
foreach ($role->getAllParentRoles() as $parentRole) {
$roleIdentifiers[] = $parentRole->getIdentifier();
}
}
}
return $roleIdentifiers;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment