-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracted menu builder from ProductCatalog package (#1344)
Extracted menu builder from ProductCatalog
- Loading branch information
1 parent
2dc387b
commit e3594d0
Showing
34 changed files
with
321 additions
and
45 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,125 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Contracts\AdminUi\Menu; | ||
|
||
use JMS\TranslationBundle\Model\Message; | ||
use Knp\Menu\ItemInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
|
||
abstract class AbstractFormContextMenuBuilder extends AbstractBuilder | ||
{ | ||
private string $formName; | ||
|
||
public function __construct( | ||
MenuItemFactoryInterface $factory, | ||
EventDispatcherInterface $eventDispatcher, | ||
string $formName | ||
) { | ||
parent::__construct($factory, $eventDispatcher); | ||
|
||
$this->formName = $formName; | ||
} | ||
|
||
/** | ||
* @return string should be lowercase alphanumeric + underscore (a-zA-Z0-9_) string | ||
*/ | ||
abstract protected static function getSidebarType(): string; | ||
|
||
protected static function getSidebarActionMessage(): string | ||
{ | ||
return 'Submit'; | ||
} | ||
|
||
protected function getConfigureEventName(): string | ||
{ | ||
return sprintf( | ||
'ibexa_admin_ui.menu_configure.%s_%s_sidebar_right', | ||
static::getSidebarType(), | ||
$this->formName, | ||
); | ||
} | ||
|
||
/** | ||
* @param array<string,mixed> $options | ||
*/ | ||
protected function createStructure(array $options): ItemInterface | ||
{ | ||
/** @var \Knp\Menu\ItemInterface|\Knp\Menu\ItemInterface[] $menu */ | ||
$menu = $this->factory->createItem('root'); | ||
|
||
$menu->addChild( | ||
$this->createMenuItem( | ||
$this->getActionItemId(), | ||
[ | ||
'label' => self::getActionLabel(), | ||
'attributes' => [ | ||
'class' => 'ibexa-btn--trigger', | ||
'data-click' => $options['submit_selector'] ?? '#', | ||
], | ||
'translation_domain' => 'ibexa_menu', | ||
] | ||
) | ||
); | ||
|
||
$menu->addChild( | ||
$this->createMenuItem( | ||
$this->getCancelItemId(), | ||
[ | ||
'label' => self::getCancelLabel(), | ||
'route' => $options['cancel_route'] ?? null, | ||
'routeParameters' => $options['cancel_route_params'] ?? [], | ||
'translation_domain' => 'ibexa_menu', | ||
] | ||
) | ||
); | ||
|
||
return $menu; | ||
} | ||
|
||
private function getActionItemId(): string | ||
{ | ||
return sprintf('%s__sidebar_right__%s', $this->formName, static::getSidebarType()); | ||
} | ||
|
||
private function getCancelItemId(): string | ||
{ | ||
return sprintf('%s__sidebar_right__cancel', $this->formName); | ||
} | ||
|
||
/** | ||
* @return \JMS\TranslationBundle\Model\Message[] | ||
*/ | ||
public static function getTranslationMessages(): array | ||
{ | ||
$actionLabel = self::getActionLabel(); | ||
$cancelLabel = self::getCancelLabel(); | ||
|
||
return [ | ||
(new Message($actionLabel, 'ibexa_menu'))->setDesc(static::getSidebarActionMessage()), | ||
(new Message($cancelLabel, 'ibexa_menu'))->setDesc('Discard'), | ||
]; | ||
} | ||
|
||
private static function getActionLabel(): string | ||
{ | ||
return sprintf( | ||
'%s_form__sidebar_right__%s', | ||
static::getSidebarType(), | ||
static::getSidebarType(), | ||
); | ||
} | ||
|
||
private static function getCancelLabel(): string | ||
{ | ||
return sprintf( | ||
'%s_form__sidebar_right__cancel', | ||
static::getSidebarType(), | ||
); | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Contracts\AdminUi\Menu; | ||
|
||
use JMS\TranslationBundle\Translation\TranslationContainerInterface; | ||
|
||
/** | ||
* Builds menu with "Copy" nad "Cancel" items. | ||
*/ | ||
final class CopyFormContextMenuBuilder extends AbstractFormContextMenuBuilder implements TranslationContainerInterface | ||
{ | ||
protected static function getSidebarType(): string | ||
{ | ||
return 'copy'; | ||
} | ||
|
||
protected static function getSidebarActionMessage(): string | ||
{ | ||
return 'Copy'; | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Contracts\AdminUi\Menu; | ||
|
||
use JMS\TranslationBundle\Translation\TranslationContainerInterface; | ||
|
||
/** | ||
* Builds menu with "Create" nad "Cancel" items. | ||
*/ | ||
final class CreateFormContextMenuBuilder extends AbstractFormContextMenuBuilder implements TranslationContainerInterface | ||
{ | ||
protected static function getSidebarType(): string | ||
{ | ||
return 'create'; | ||
} | ||
|
||
protected static function getSidebarActionMessage(): string | ||
{ | ||
return 'Save and close'; | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
|
||
namespace Ibexa\Contracts\AdminUi\Menu; | ||
|
||
use Knp\Menu\FactoryInterface; | ||
use Knp\Menu\ItemInterface; | ||
|
||
interface MenuItemFactoryInterface extends FactoryInterface | ||
{ | ||
/** | ||
* Creates Location menu item only when user has content:read permission. | ||
* | ||
* @param array<mixed> $options | ||
* | ||
* @return \Knp\Menu\ItemInterface|null | ||
*/ | ||
public function createLocationMenuItem(string $name, int $locationId, array $options = []): ?ItemInterface; | ||
} |
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,27 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Contracts\AdminUi\Menu; | ||
|
||
use JMS\TranslationBundle\Translation\TranslationContainerInterface; | ||
|
||
/** | ||
* Builds menu with "Update" nad "Cancel" items. | ||
*/ | ||
final class UpdateFormContextMenuBuilder extends AbstractFormContextMenuBuilder implements TranslationContainerInterface | ||
{ | ||
protected static function getSidebarType(): string | ||
{ | ||
return 'update'; | ||
} | ||
|
||
protected static function getSidebarActionMessage(): string | ||
{ | ||
return 'Save and close'; | ||
} | ||
} |
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.