-
Notifications
You must be signed in to change notification settings - Fork 0
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
18 changed files
with
314 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Pixel\EventBundle\Admin; | ||
|
||
use Pixel\EventBundle\Entity\Setting; | ||
use Sulu\Bundle\AdminBundle\Admin\Admin; | ||
use Sulu\Bundle\AdminBundle\Admin\Navigation\NavigationItem; | ||
use Sulu\Bundle\AdminBundle\Admin\Navigation\NavigationItemCollection; | ||
use Sulu\Bundle\AdminBundle\Admin\View\ToolbarAction; | ||
use Sulu\Bundle\AdminBundle\Admin\View\ViewBuilderFactoryInterface; | ||
use Sulu\Bundle\AdminBundle\Admin\View\ViewCollection; | ||
use Sulu\Component\Security\Authorization\PermissionTypes; | ||
use Sulu\Component\Security\Authorization\SecurityCheckerInterface; | ||
|
||
class SettingAdmin extends Admin | ||
{ | ||
const TAB_VIEW = "event.settings"; | ||
const FORM_VIEW = "event.settings.form"; | ||
|
||
private ViewBuilderFactoryInterface $viewBuilderFactory; | ||
private SecurityCheckerInterface $securityChecker; | ||
|
||
public function __construct( | ||
ViewBuilderFactoryInterface $viewBuilderFactory, | ||
SecurityCheckerInterface $securityChecker | ||
) | ||
{ | ||
$this->viewBuilderFactory = $viewBuilderFactory; | ||
$this->securityChecker = $securityChecker; | ||
} | ||
|
||
public function configureNavigationItems(NavigationItemCollection $navigationItemCollection): void | ||
{ | ||
if($this->securityChecker->hasPermission(Setting::SECURITY_CONTEXT, PermissionTypes::EDIT)){ | ||
$navigationItem = new NavigationItem('event.settings'); | ||
$navigationItem->setPosition(2); | ||
$navigationItem->setView(static::TAB_VIEW); | ||
$navigationItemCollection->get(Admin::SETTINGS_NAVIGATION_ITEM)->addChild($navigationItem); | ||
} | ||
} | ||
|
||
public function configureViews(ViewCollection $viewCollection): void | ||
{ | ||
if($this->securityChecker->hasPermission(Setting::SECURITY_CONTEXT, PermissionTypes::EDIT)){ | ||
$viewCollection->add( | ||
$this->viewBuilderFactory->createResourceTabViewBuilder(static::TAB_VIEW, '/event-settings/:id') | ||
->setResourceKey(Setting::RESOURCE_KEY) | ||
->setAttributeDefault('id', '-') | ||
); | ||
$viewCollection->add( | ||
$this->viewBuilderFactory->createFormViewBuilder(static::FORM_VIEW, '/details') | ||
->setResourceKey(Setting::RESOURCE_KEY) | ||
->setFormKey(Setting::FORM_KEY) | ||
->setTabTitle('sulu_admin.details') | ||
->addToolbarActions([new ToolbarAction('sulu_admin.save')]) | ||
->setParent(static::TAB_VIEW) | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
public function getSecurityContexts() | ||
{ | ||
return [ | ||
self::SULU_ADMIN_SECURITY_SYSTEM => [ | ||
'Setting' => [ | ||
Setting::SECURITY_CONTEXT => [ | ||
PermissionTypes::VIEW, | ||
PermissionTypes::EDIT | ||
] | ||
] | ||
] | ||
]; | ||
} | ||
} |
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,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Pixel\EventBundle\Controller\Admin; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use FOS\RestBundle\View\ViewHandlerInterface; | ||
use HandcraftedInTheAlps\RestRoutingBundle\Controller\Annotations\RouteResource; | ||
use HandcraftedInTheAlps\RestRoutingBundle\Routing\ClassResourceInterface; | ||
use Pixel\EventBundle\Entity\Setting; | ||
use Sulu\Bundle\MediaBundle\Media\Manager\MediaManagerInterface; | ||
use Sulu\Component\Rest\AbstractRestController; | ||
use Sulu\Component\Security\SecuredControllerInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; | ||
|
||
/** | ||
* @RouteResource("event-settings") | ||
*/ | ||
class SettingController extends AbstractRestController implements ClassResourceInterface, SecuredControllerInterface | ||
{ | ||
private EntityManagerInterface $entityManager; | ||
private MediaManagerInterface $mediaManager; | ||
|
||
public function __construct( | ||
EntityManagerInterface $entityManager, | ||
MediaManagerInterface $mediaManager, | ||
ViewHandlerInterface $viewHandler, | ||
?TokenStorageInterface $tokenStorage = null | ||
) | ||
{ | ||
$this->entityManager = $entityManager; | ||
$this->mediaManager = $mediaManager; | ||
parent::__construct($viewHandler, $tokenStorage); | ||
} | ||
|
||
public function getAction(): Response | ||
{ | ||
$applicationSetting = $this->entityManager->getRepository(Setting::class)->findOneBy([]); | ||
return $this->handleView($this->view($applicationSetting ?: new Setting())); | ||
} | ||
|
||
public function putAction(Request $request): Response | ||
{ | ||
$applicationSetting = $this->entityManager->getRepository(Setting::class)->findOneBy([]); | ||
if(!$applicationSetting){ | ||
$applicationSetting = new Setting(); | ||
$this->entityManager->persist($applicationSetting); | ||
} | ||
$this->mapDataToEntity($request->request->all(), $applicationSetting); | ||
$this->entityManager->flush(); | ||
return $this->handleView($this->view($applicationSetting)); | ||
} | ||
|
||
public function mapDataToEntity(array $data, Setting $entity): void | ||
{ | ||
$defaultImageId = $data['defaultImage']['id'] ?? null; | ||
|
||
$entity->setDefaultImage($defaultImageId ? $this->mediaManager->getEntityById($defaultImageId) : null); | ||
} | ||
|
||
public function getSecurityContext() | ||
{ | ||
return Setting::SECURITY_CONTEXT; | ||
} | ||
} |
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
Oops, something went wrong.