This repository has been archived by the owner on Jul 22, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
942 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
.. index:: | ||
single: Profile | ||
|
||
======= | ||
Profile | ||
======= | ||
|
||
Architecture | ||
============ | ||
|
||
For more information about our position regarding *product* architecture, you can read: :doc:`../architecture/product`. | ||
|
||
FOSUSerBundle / SonataUserBundle integration | ||
============================================ | ||
|
||
To enhance your project integrations with third parties bundles, the ``SonataProfileBundle`` has extendable menu and templates. | ||
|
||
You can easily add your user profile to the shop profile by extending menu (exemple below) and ``@SonataProfile/action.html.twig`` template. | ||
|
||
Configuration | ||
============= | ||
|
||
The bundle allows you to configure the menu and the dashboard blocks. | ||
|
||
.. code-block:: yaml | ||
sonata_profile: | ||
override_sonata_user_bundle_profile: false | ||
template: 'SonataProfileBundle::action.html.twig' | ||
dashboard: | ||
blocks: | ||
- { position: left, type: sonata.block.service.text, settings: { content: "<h2>Welcome!</h2> <p>This is a sample shop profile dashboard, feel free to override it in the configuration! Want to make this text dynamic? For instance display the user's name? Create a dedicated block and edit the configuration!</p>"} } | ||
- { position: left, type: sonata.order.block.recent_orders, settings: { title: Recent Orders, number: 5, mode: public }} | ||
#- { position: right, type: sonata.timeline.block.timeline, settings: { max_per_page: 15 }} | ||
- { position: right, type: sonata.news.block.recent_posts, settings: { title: Recent Posts, number: 5, mode: public }} | ||
- { position: right, type: sonata.news.block.recent_comments, settings: { title: Recent Comments, number: 5, mode: public }} | ||
menu: | ||
- { route: 'sonata_profile_dashboard', label: 'Dashboard', domain: 'SonataProfileBundle'} | ||
# You can add user profile here | ||
#- { route: 'fos_user_profile_edit', label: 'link_edit_profile', domain: 'SonataUserBundle'} | ||
#- { route: 'fos_user_change_password', label: 'title_user_edit_password', domain: 'SonataUserBundle'} | ||
- { route: 'sonata_customer_addresses', label: 'link_list_addresses', domain: 'SonataCustomerBundle'} | ||
- { route: 'sonata_order_index', label: 'order_list', domain: 'SonataOrderBundle'} | ||
Blocks | ||
====== | ||
|
||
``SonataProfileBundle`` comes with some blocks services: | ||
|
||
* ``AccountBlockService``: display the logged in user. | ||
* ``ProfileMenuBlickService``: display the menu added to the bundle configuration. |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\ProfileBundle\Block; | ||
|
||
use Sonata\BlockBundle\Block\BlockContextInterface; | ||
use Sonata\BlockBundle\Block\Service\AbstractAdminBlockService; | ||
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
|
||
/** | ||
* Render a block with the connection option or the login name. | ||
* | ||
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org> | ||
*/ | ||
final class AccountBlockService extends AbstractAdminBlockService | ||
{ | ||
/** | ||
* @var TokenStorageInterface | ||
*/ | ||
private $tokenStorage; | ||
|
||
public function __construct(string $name, EngineInterface $templating, TokenStorageInterface $tokenStorage) | ||
{ | ||
parent::__construct($name, $templating); | ||
|
||
$this->tokenStorage = $tokenStorage; | ||
} | ||
|
||
public function execute(BlockContextInterface $blockContext, Response $response = null) | ||
{ | ||
$user = false; | ||
if ($this->tokenStorage->getToken()) { | ||
$user = $this->tokenStorage->getToken()->getUser(); | ||
} | ||
|
||
if (!$user instanceof UserInterface) { | ||
$user = false; | ||
} | ||
|
||
return $this->renderPrivateResponse($blockContext->getTemplate(), [ | ||
'user' => $user, | ||
'block' => $blockContext->getBlock(), | ||
'context' => $blockContext, | ||
]); | ||
} | ||
|
||
public function configureSettings(OptionsResolver $resolver) | ||
{ | ||
$resolver->setDefaults([ | ||
'template' => 'SonataProfileBundle:Block:account.html.twig', | ||
'ttl' => 0, | ||
]); | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'Account Block'; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\ProfileBundle\Block; | ||
|
||
use Knp\Menu\Provider\MenuProviderInterface; | ||
use Sonata\BlockBundle\Block\BlockContextInterface; | ||
use Sonata\BlockBundle\Block\Service\MenuBlockService; | ||
use Sonata\ProfileBundle\Menu\ProfileMenuBuilder; | ||
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
/** | ||
* @author Hugo Briand <briand@ekino.com> | ||
*/ | ||
final class ProfileMenuBlockService extends MenuBlockService | ||
{ | ||
/** | ||
* @var ProfileMenuBuilder | ||
*/ | ||
private $menuBuilder; | ||
|
||
public function __construct(string $name, EngineInterface $templating, MenuProviderInterface $menuProvider, ProfileMenuBuilder $menuBuilder) | ||
{ | ||
parent::__construct($name, $templating, $menuProvider, []); | ||
|
||
$this->menuBuilder = $menuBuilder; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'Ecommerce Profile Menu'; | ||
} | ||
|
||
public function configureSettings(OptionsResolver $resolver) | ||
{ | ||
parent::configureSettings($resolver); | ||
|
||
$resolver->setDefaults([ | ||
'cache_policy' => 'private', | ||
'menu_template' => 'SonataBlockBundle:Block:block_side_menu_template.html.twig', | ||
]); | ||
} | ||
|
||
protected function getMenu(BlockContextInterface $blockContext) | ||
{ | ||
$settings = $blockContext->getSettings(); | ||
|
||
$menu = parent::getMenu($blockContext); | ||
|
||
if (null === $menu || '' === $menu) { | ||
$menu = $this->menuBuilder->createProfileMenu( | ||
[ | ||
'childrenAttributes' => ['class' => $settings['menu_class']], | ||
'attributes' => ['class' => $settings['children_class']], | ||
] | ||
); | ||
|
||
if (method_exists($menu, 'setCurrentUri')) { | ||
$menu->setCurrentUri($settings['current_uri']); | ||
} | ||
} | ||
|
||
return $menu; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\ProfileBundle\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Security\Core\Exception\AccessDeniedException; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
|
||
/** | ||
* This class is inspired from the FOS Profile Controller, except : | ||
* - only twig is supported | ||
* - separation of the user authentication form with the profile form. | ||
*/ | ||
final class ProfileController extends Controller | ||
{ | ||
/** | ||
* @throws AccessDeniedException | ||
*/ | ||
public function dashboardAction(): Response | ||
{ | ||
$user = $this->getUser(); | ||
if (!\is_object($user) || !$user instanceof UserInterface) { | ||
throw new AccessDeniedException('This user does not have access to this section.'); | ||
} | ||
|
||
return $this->render('SonataProfileBundle::dashboard.html.twig', [ | ||
'user' => $user, | ||
'blocks' => $this->container->getParameter('sonata.profile.configuration.profile_blocks'), | ||
]); | ||
} | ||
} |
Oops, something went wrong.