diff --git a/src/bundle/Resources/config/services/menu.yaml b/src/bundle/Resources/config/services/menu.yaml index 245b953aef..12bc7f0f78 100644 --- a/src/bundle/Resources/config/services/menu.yaml +++ b/src/bundle/Resources/config/services/menu.yaml @@ -10,6 +10,12 @@ services: Ibexa\AdminUi\Menu\MenuItemFactory: ~ + # + # Right Sidebar Label Factory + # + + Ibexa\AdminUi\Menu\ContentRightSidebarLabelFactory: ~ + # # Menu Builders # diff --git a/src/bundle/Resources/translations/ibexa_menu.en.xliff b/src/bundle/Resources/translations/ibexa_menu.en.xliff index 2cf37fd744..4406079db3 100644 --- a/src/bundle/Resources/translations/ibexa_menu.en.xliff +++ b/src/bundle/Resources/translations/ibexa_menu.en.xliff @@ -471,6 +471,16 @@ Save and close key: section_edit__sidebar_right__save_and_close + + Create + Create + key: sidebar_right.create + + + Create content + Create content + key: sidebar_right.create_content + Create user Create user diff --git a/src/lib/Menu/ContentRightSidebarBuilder.php b/src/lib/Menu/ContentRightSidebarBuilder.php index c92703d22b..d1beeeabb3 100644 --- a/src/lib/Menu/ContentRightSidebarBuilder.php +++ b/src/lib/Menu/ContentRightSidebarBuilder.php @@ -50,8 +50,6 @@ class ContentRightSidebarBuilder extends AbstractBuilder implements TranslationC public const ITEM__REVEAL = 'content__sidebar_right__reveal'; public const ITEM__INVITE = 'content__sidebar_right__invite'; - private const CREATE_USER_LABEL = 'sidebar_right.create_user'; - /** @var \Ibexa\Contracts\Core\Repository\PermissionResolver */ private $permissionResolver; @@ -72,6 +70,8 @@ class ContentRightSidebarBuilder extends AbstractBuilder implements TranslationC private SiteaccessResolverInterface $siteaccessResolver; + private ContentRightSidebarLabelFactoryInterface $labelFactory; + public function __construct( MenuItemFactory $factory, EventDispatcherInterface $eventDispatcher, @@ -81,7 +81,8 @@ public function __construct( LocationService $locationService, UniversalDiscoveryExtension $udwExtension, PermissionCheckerInterface $permissionChecker, - SiteaccessResolverInterface $siteaccessResolver + SiteaccessResolverInterface $siteaccessResolver, + ContentRightSidebarLabelFactory $labelFactory ) { parent::__construct($factory, $eventDispatcher); @@ -92,6 +93,7 @@ public function __construct( $this->udwExtension = $udwExtension; $this->permissionChecker = $permissionChecker; $this->siteaccessResolver = $siteaccessResolver; + $this->labelFactory = $labelFactory; } /** @@ -197,7 +199,7 @@ public function createStructure(array $options): ItemInterface 'attributes' => $canCreate ? $createAttributes : array_merge($createAttributes, ['disabled' => 'disabled']), - 'label' => $contentIsUserGroup ? self::CREATE_USER_LABEL : self::ITEM__CREATE, + 'label' => $this->labelFactory->createLabel($contentType), ] ), ]); @@ -318,7 +320,6 @@ public static function getTranslationMessages(): array { return [ (new Message(self::ITEM__CREATE, 'ibexa_menu'))->setDesc('Create content'), - (new Message(self::CREATE_USER_LABEL, 'ibexa_menu'))->setDesc('Create user'), (new Message(self::ITEM__EDIT, 'ibexa_menu'))->setDesc('Edit'), (new Message(self::ITEM__PREVIEW, 'ibexa_menu'))->setDesc('Preview'), (new Message(self::ITEM__SEND_TO_TRASH, 'ibexa_menu'))->setDesc('Send to trash'), diff --git a/src/lib/Menu/ContentRightSidebarLabelFactory.php b/src/lib/Menu/ContentRightSidebarLabelFactory.php new file mode 100644 index 0000000000..a4579c85dc --- /dev/null +++ b/src/lib/Menu/ContentRightSidebarLabelFactory.php @@ -0,0 +1,76 @@ +configResolver = $configResolver; + } + + /** + * Returns label based on content type. + * + * @param \Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType $contentType + * + * @return string + * + * @throws \Ibexa\AdminUi\Exception\InvalidArgumentException + */ + public function createLabel(ContentType $contentType): string + { + switch (true) { + case $this->isUserGroup($contentType): + return self::CREATE_USER; + case $this->isDashboard($contentType): + return self::CREATE; + default: + return self::CREATE_CONTENT; + } + } + + private function isUserGroup(ContentType $contentType): bool + { + return (new ContentTypeIsUserGroup($this->configResolver->getParameter('user_group_content_type_identifier')))->isSatisfiedBy($contentType); + } + + private function isDashboard(ContentType $contentType): bool + { + return (new ContentTypeIsDashboardContainer($this->configResolver->getParameter('dashboard.container_content_type_identifier')))->isSatisfiedBy($contentType); + } + + /** + * @return \JMS\TranslationBundle\Model\Message[] + */ + public static function getTranslationMessages(): array + { + return [ + (new Message(self::CREATE_CONTENT, 'ibexa_menu'))->setDesc('Create content'), + (new Message(self::CREATE_USER, 'ibexa_menu'))->setDesc('Create user'), + (new Message(self::CREATE, 'ibexa_menu'))->setDesc('Create'), + ]; + } +} + +class_alias(ContentRightSidebarLabelFactory::class, 'EzSystems\EzPlatformAdminUi\Menu\ContentRightSidebarLabelFactory'); diff --git a/src/lib/Menu/ContentRightSidebarLabelFactoryInterface.php b/src/lib/Menu/ContentRightSidebarLabelFactoryInterface.php new file mode 100644 index 0000000000..b178e66843 --- /dev/null +++ b/src/lib/Menu/ContentRightSidebarLabelFactoryInterface.php @@ -0,0 +1,18 @@ +