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