From be6aeeaff67ce0266a46b8add39e97d82a16a424 Mon Sep 17 00:00:00 2001
From: Robert Swoboda <53216935+Gengar-i@users.noreply.github.com>
Date: Tue, 5 Mar 2024 18:27:15 +0100
Subject: [PATCH 1/4] IBX-7895: Added possibility to change create content
 button label

---
 .../Resources/config/services/menu.yaml       |  6 ++
 .../translations/ibexa_menu.en.xliff          |  5 --
 src/lib/Menu/ContentRightSidebarBuilder.php   | 12 +--
 .../Menu/ContentRightSidebarLabelFactory.php  | 75 +++++++++++++++++++
 ...ntentRightSidebarLabelFactoryInterface.php | 18 +++++
 .../ContentTypeIsDashboardContainer.php       | 48 ++++++++++++
 6 files changed, 154 insertions(+), 10 deletions(-)
 create mode 100644 src/lib/Menu/ContentRightSidebarLabelFactory.php
 create mode 100644 src/lib/Menu/ContentRightSidebarLabelFactoryInterface.php
 create mode 100644 src/lib/Specification/ContentType/ContentTypeIsDashboardContainer.php

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..29968808bf 100644
--- a/src/bundle/Resources/translations/ibexa_menu.en.xliff
+++ b/src/bundle/Resources/translations/ibexa_menu.en.xliff
@@ -471,11 +471,6 @@
         <target state="new">Save and close</target>
         <note>key: section_edit__sidebar_right__save_and_close</note>
       </trans-unit>
-      <trans-unit id="54d372f047fb6efb83ac05eca195c8c891edc64a" resname="sidebar_right.create_user">
-        <source>Create user</source>
-        <target state="new">Create user</target>
-        <note>key: sidebar_right.create_user</note>
-      </trans-unit>
       <trans-unit id="ae876d2c3fdb4f08383aefae6106b69dfe124b38" resname="trash__sidebar_right__empty_trash">
         <source>Empty Trash</source>
         <target state="new">Empty Trash</target>
diff --git a/src/lib/Menu/ContentRightSidebarBuilder.php b/src/lib/Menu/ContentRightSidebarBuilder.php
index c92703d22b..24386d3d9c 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;
     }
 
     /**
@@ -188,6 +190,7 @@ public function createStructure(array $options): ItemInterface
             ->isSatisfiedBy($contentType);
         $contentIsUserGroup = (new ContentTypeIsUserGroup($this->configResolver->getParameter('user_group_content_type_identifier')))
             ->isSatisfiedBy($contentType);
+        $label = $this->labelFactory->createLabel($contentType);
 
         $menu->setChildren([
             self::ITEM__CREATE => $this->createMenuItem(
@@ -197,7 +200,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' => $label
                 ]
             ),
         ]);
@@ -318,7 +321,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..6216e7a50e
--- /dev/null
+++ b/src/lib/Menu/ContentRightSidebarLabelFactory.php
@@ -0,0 +1,75 @@
+<?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\AdminUi\Menu;
+
+use Ibexa\AdminUi\Specification\ContentType\ContentTypeIsUserGroup;
+use Ibexa\AdminUi\Specification\ContentType\ContentTypeIsDashboardContainer;
+use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
+use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
+use JMS\TranslationBundle\Model\Message;
+
+final class ContentRightSidebarLabelFactory implements ContentRightSidebarLabelFactoryInterface
+{
+    public const CREATE = 'sidebar_right.create';
+    public const CREATE_CONTENT = 'sidebar_right.create_content';
+    public const CREATE_USER = 'sidebar_right.create_user';
+
+    /** @var \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface */
+    private $configResolver;
+
+    public function __construct(ConfigResolverInterface $configResolver)
+    {
+        $this->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 @@
+<?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\AdminUi\Menu;
+
+use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
+
+interface ContentRightSidebarLabelFactoryInterface
+{
+    public function createLabel(ContentType $contentType): string;
+}
+
+class_alias(ContentRightSidebarLabelFactoryInterface::class, 'EzSystems\EzPlatformAdminUi\Menu\ContentRightSidebarLabelFactoryInterface');
diff --git a/src/lib/Specification/ContentType/ContentTypeIsDashboardContainer.php b/src/lib/Specification/ContentType/ContentTypeIsDashboardContainer.php
new file mode 100644
index 0000000000..bbfe81998c
--- /dev/null
+++ b/src/lib/Specification/ContentType/ContentTypeIsDashboardContainer.php
@@ -0,0 +1,48 @@
+<?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\AdminUi\Specification\ContentType;
+
+use Ibexa\AdminUi\Exception\InvalidArgumentException;
+use Ibexa\AdminUi\Specification\AbstractSpecification;
+use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
+
+class ContentTypeIsDashboardContainer extends AbstractSpecification
+{
+    /** @var string */
+    private $dashboardGroupContentTypeIdentifier;
+
+    /**
+     * @param string $dashboardGroupContentTypeIdentifier
+     */
+    public function __construct(string $dashboardGroupContentTypeIdentifier)
+    {
+        $this->dashboardGroupContentTypeIdentifier = $dashboardGroupContentTypeIdentifier;
+    }
+
+    /**
+     * Checks if $contentType is an existing User content.
+     *
+     * @param \Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType $contentType
+     *
+     * @return bool
+     *
+     * @throws \Ibexa\AdminUi\Exception\InvalidArgumentException
+     */
+    public function isSatisfiedBy($contentType): bool
+    {
+        if (!$contentType instanceof ContentType) {
+            throw new InvalidArgumentException($contentType, sprintf('Must be an instance of %s', ContentType::class));
+        }
+        dump($this->dashboardGroupContentTypeIdentifier);
+
+        return $contentType->identifier === $this->dashboardGroupContentTypeIdentifier;
+    }
+}
+
+class_alias(ContentTypeIsDashboardContainer::class, 'EzSystems\EzPlatformAdminUi\Specification\ContentType\ContentTypeIsDashboardContainer');

From 295ee44707a984b0406262998ae9c73abd795027 Mon Sep 17 00:00:00 2001
From: Robert Swoboda <53216935+Gengar-i@users.noreply.github.com>
Date: Tue, 5 Mar 2024 18:32:19 +0100
Subject: [PATCH 2/4] Remove label varaible

---
 src/lib/Menu/ContentRightSidebarBuilder.php | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/lib/Menu/ContentRightSidebarBuilder.php b/src/lib/Menu/ContentRightSidebarBuilder.php
index 24386d3d9c..d1beeeabb3 100644
--- a/src/lib/Menu/ContentRightSidebarBuilder.php
+++ b/src/lib/Menu/ContentRightSidebarBuilder.php
@@ -190,7 +190,6 @@ public function createStructure(array $options): ItemInterface
             ->isSatisfiedBy($contentType);
         $contentIsUserGroup = (new ContentTypeIsUserGroup($this->configResolver->getParameter('user_group_content_type_identifier')))
             ->isSatisfiedBy($contentType);
-        $label = $this->labelFactory->createLabel($contentType);
 
         $menu->setChildren([
             self::ITEM__CREATE => $this->createMenuItem(
@@ -200,7 +199,7 @@ public function createStructure(array $options): ItemInterface
                     'attributes' => $canCreate
                         ? $createAttributes
                         : array_merge($createAttributes, ['disabled' => 'disabled']),
-                    'label' => $label
+                    'label' => $this->labelFactory->createLabel($contentType),
                 ]
             ),
         ]);

From 22da78360bd0d361c3a866b8937e9adec7defb57 Mon Sep 17 00:00:00 2001
From: Robert Swoboda <53216935+Gengar-i@users.noreply.github.com>
Date: Wed, 6 Mar 2024 10:47:29 +0100
Subject: [PATCH 3/4] Removed dashboard check from admin-ui

---
 .../translations/ibexa_menu.en.xliff          | 15 ++++++
 .../Menu/ContentRightSidebarLabelFactory.php  |  3 +-
 .../ContentTypeIsDashboardContainer.php       | 48 -------------------
 3 files changed, 17 insertions(+), 49 deletions(-)
 delete mode 100644 src/lib/Specification/ContentType/ContentTypeIsDashboardContainer.php

diff --git a/src/bundle/Resources/translations/ibexa_menu.en.xliff b/src/bundle/Resources/translations/ibexa_menu.en.xliff
index 29968808bf..4406079db3 100644
--- a/src/bundle/Resources/translations/ibexa_menu.en.xliff
+++ b/src/bundle/Resources/translations/ibexa_menu.en.xliff
@@ -471,6 +471,21 @@
         <target state="new">Save and close</target>
         <note>key: section_edit__sidebar_right__save_and_close</note>
       </trans-unit>
+      <trans-unit id="db0f50e15d8842dd4bdfbf8e3ba87433effde5d1" resname="sidebar_right.create">
+        <source>Create</source>
+        <target state="new">Create</target>
+        <note>key: sidebar_right.create</note>
+      </trans-unit>
+      <trans-unit id="e0640245c9f51b4a109796d797654742254056f5" resname="sidebar_right.create_content">
+        <source>Create content</source>
+        <target state="new">Create content</target>
+        <note>key: sidebar_right.create_content</note>
+      </trans-unit>
+      <trans-unit id="54d372f047fb6efb83ac05eca195c8c891edc64a" resname="sidebar_right.create_user">
+        <source>Create user</source>
+        <target state="new">Create user</target>
+        <note>key: sidebar_right.create_user</note>
+      </trans-unit>
       <trans-unit id="ae876d2c3fdb4f08383aefae6106b69dfe124b38" resname="trash__sidebar_right__empty_trash">
         <source>Empty Trash</source>
         <target state="new">Empty Trash</target>
diff --git a/src/lib/Menu/ContentRightSidebarLabelFactory.php b/src/lib/Menu/ContentRightSidebarLabelFactory.php
index 6216e7a50e..e5560bbf02 100644
--- a/src/lib/Menu/ContentRightSidebarLabelFactory.php
+++ b/src/lib/Menu/ContentRightSidebarLabelFactory.php
@@ -13,8 +13,9 @@
 use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
 use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
 use JMS\TranslationBundle\Model\Message;
+use JMS\TranslationBundle\Translation\TranslationContainerInterface;
 
-final class ContentRightSidebarLabelFactory implements ContentRightSidebarLabelFactoryInterface
+final class ContentRightSidebarLabelFactory implements ContentRightSidebarLabelFactoryInterface, TranslationContainerInterface
 {
     public const CREATE = 'sidebar_right.create';
     public const CREATE_CONTENT = 'sidebar_right.create_content';
diff --git a/src/lib/Specification/ContentType/ContentTypeIsDashboardContainer.php b/src/lib/Specification/ContentType/ContentTypeIsDashboardContainer.php
deleted file mode 100644
index bbfe81998c..0000000000
--- a/src/lib/Specification/ContentType/ContentTypeIsDashboardContainer.php
+++ /dev/null
@@ -1,48 +0,0 @@
-<?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\AdminUi\Specification\ContentType;
-
-use Ibexa\AdminUi\Exception\InvalidArgumentException;
-use Ibexa\AdminUi\Specification\AbstractSpecification;
-use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
-
-class ContentTypeIsDashboardContainer extends AbstractSpecification
-{
-    /** @var string */
-    private $dashboardGroupContentTypeIdentifier;
-
-    /**
-     * @param string $dashboardGroupContentTypeIdentifier
-     */
-    public function __construct(string $dashboardGroupContentTypeIdentifier)
-    {
-        $this->dashboardGroupContentTypeIdentifier = $dashboardGroupContentTypeIdentifier;
-    }
-
-    /**
-     * Checks if $contentType is an existing User content.
-     *
-     * @param \Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType $contentType
-     *
-     * @return bool
-     *
-     * @throws \Ibexa\AdminUi\Exception\InvalidArgumentException
-     */
-    public function isSatisfiedBy($contentType): bool
-    {
-        if (!$contentType instanceof ContentType) {
-            throw new InvalidArgumentException($contentType, sprintf('Must be an instance of %s', ContentType::class));
-        }
-        dump($this->dashboardGroupContentTypeIdentifier);
-
-        return $contentType->identifier === $this->dashboardGroupContentTypeIdentifier;
-    }
-}
-
-class_alias(ContentTypeIsDashboardContainer::class, 'EzSystems\EzPlatformAdminUi\Specification\ContentType\ContentTypeIsDashboardContainer');

From 32a79e8dcb9a0011f1e3d16fbb07fd250d3eaa93 Mon Sep 17 00:00:00 2001
From: Robert Swoboda <53216935+Gengar-i@users.noreply.github.com>
Date: Wed, 6 Mar 2024 15:02:50 +0100
Subject: [PATCH 4/4] Fixed import

---
 src/lib/Menu/ContentRightSidebarLabelFactory.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lib/Menu/ContentRightSidebarLabelFactory.php b/src/lib/Menu/ContentRightSidebarLabelFactory.php
index e5560bbf02..a4579c85dc 100644
--- a/src/lib/Menu/ContentRightSidebarLabelFactory.php
+++ b/src/lib/Menu/ContentRightSidebarLabelFactory.php
@@ -9,7 +9,7 @@
 namespace Ibexa\AdminUi\Menu;
 
 use Ibexa\AdminUi\Specification\ContentType\ContentTypeIsUserGroup;
-use Ibexa\AdminUi\Specification\ContentType\ContentTypeIsDashboardContainer;
+use Ibexa\Dashboard\Specification\ContentTypeIsDashboardContainer;
 use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
 use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
 use JMS\TranslationBundle\Model\Message;