mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2024-12-04 23:17:19 +01:00
Implemented user source to menu
This commit is contained in:
parent
1aa5d35169
commit
a11296df5b
@ -109,17 +109,28 @@ class UserMenuSubscriber extends AbstractEntityMenuSubscriber implements EventSu
|
||||
$slug = $fixtureSource::getSlug();
|
||||
$name = $fixtureSource->getName();
|
||||
$icon = $fixtureSource::getIcon();
|
||||
$item->addChild($this->trans($name), [
|
||||
$item->addChild($this->trans($name), $this->getSourceItemConfigurationArray($slug, $icon));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $identity
|
||||
* @param string $icon
|
||||
*
|
||||
* @return []
|
||||
*/
|
||||
private function getSourceItemConfigurationArray(string $identity, string $icon)
|
||||
{
|
||||
return [
|
||||
'route' => self::LAYER_GET_ROUTE,
|
||||
'routeParameters' => [
|
||||
LayerController::IDENTITY_PARAMETER_KEY => $slug,
|
||||
LayerController::IDENTITY_PARAMETER_KEY => $identity,
|
||||
LayerController::FORMAT_PARAMETER_KEY => RESTResponseType::HTML,
|
||||
LayerController::LAYER_PARAMETER_KEY => LayerType::SOURCE,
|
||||
],
|
||||
'attributes' => [
|
||||
'icon' => $icon,
|
||||
],
|
||||
]);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -177,6 +188,10 @@ class UserMenuSubscriber extends AbstractEntityMenuSubscriber implements EventSu
|
||||
'divider_append' => true,
|
||||
],
|
||||
]);
|
||||
$userSource = $this->getToken()->getUser()->getSource();
|
||||
$identity = $userSource->getId();
|
||||
$icon = 'fas fa-user';
|
||||
$dropdown->addChild($this->trans('user source'), $this->getSourceItemConfigurationArray($identity, $icon));
|
||||
} else {
|
||||
$dropdown->addChild($this->trans('login'), [
|
||||
'route' => 'fos_user_security_login',
|
||||
|
@ -14,6 +14,7 @@ use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInt
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Infinito\Domain\FixtureManagement\FixtureSource\GuestUserFixtureSource;
|
||||
use Infinito\Entity\User;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@ -54,6 +55,9 @@ class UserMenuSubscriberIntegrationTest extends KernelTestCase
|
||||
$token = $this->createMock(TokenInterface::class);
|
||||
$token->method('getRoles')->willReturn([new Role('test_role')]);
|
||||
$token->method('getUsername')->willReturn('test_user');
|
||||
$user = new User();
|
||||
$user->getSource()->setId(123);
|
||||
$token->method('getUser')->willReturn($user);
|
||||
$this->tokenStorage->setToken($token);
|
||||
$factory = new MenuFactory();
|
||||
$item = new MenuItem('test', $factory);
|
||||
@ -63,7 +67,7 @@ class UserMenuSubscriberIntegrationTest extends KernelTestCase
|
||||
$menuEvent = new MenuEvent($factory, $item, $requests);
|
||||
$this->subscriber->onUserMenuConfigure($menuEvent);
|
||||
$children = $menuEvent->getItem()->getChildren()['test_user']->getChildren();
|
||||
$authentificatedItems = ['logout', 'edit profile'];
|
||||
$authentificatedItems = ['logout', 'edit profile', 'user source'];
|
||||
foreach ($authentificatedItems as $key) {
|
||||
$this->assertInstanceOf(MenuItem::class, $children[$key]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user