Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-7895: Added possibility to change create content button label #1200

Draft
wants to merge 4 commits into
base: 4.6
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/bundle/Resources/config/services/menu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ services:

Ibexa\AdminUi\Menu\MenuItemFactory: ~

#
# Right Sidebar Label Factory
#
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my pov, this comment adds no value.


Ibexa\AdminUi\Menu\ContentRightSidebarLabelFactory: ~

#
# Menu Builders
#
Expand Down
10 changes: 10 additions & 0 deletions src/bundle/Resources/translations/ibexa_menu.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,16 @@
<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>
Expand Down
11 changes: 6 additions & 5 deletions src/lib/Menu/ContentRightSidebarBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -72,6 +70,8 @@ class ContentRightSidebarBuilder extends AbstractBuilder implements TranslationC

private SiteaccessResolverInterface $siteaccessResolver;

private ContentRightSidebarLabelFactoryInterface $labelFactory;

public function __construct(
MenuItemFactory $factory,
EventDispatcherInterface $eventDispatcher,
Expand All @@ -81,7 +81,8 @@ public function __construct(
LocationService $locationService,
UniversalDiscoveryExtension $udwExtension,
PermissionCheckerInterface $permissionChecker,
SiteaccessResolverInterface $siteaccessResolver
SiteaccessResolverInterface $siteaccessResolver,
ContentRightSidebarLabelFactory $labelFactory
) {
parent::__construct($factory, $eventDispatcher);

Expand All @@ -92,6 +93,7 @@ public function __construct(
$this->udwExtension = $udwExtension;
$this->permissionChecker = $permissionChecker;
$this->siteaccessResolver = $siteaccessResolver;
$this->labelFactory = $labelFactory;
}

/**
Expand Down Expand Up @@ -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),
]
),
]);
Expand Down Expand Up @@ -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'),
Expand Down
76 changes: 76 additions & 0 deletions src/lib/Menu/ContentRightSidebarLabelFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

Check warning on line 1 in src/lib/Menu/ContentRightSidebarLabelFactory.php

View workflow job for this annotation

GitHub Actions / Run code style check (8.0)

Found violation(s) of type: ordered_imports

/**
* @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\Dashboard\Specification\ContentTypeIsDashboardContainer;
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, TranslationContainerInterface
{
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private $configResolver;
private ConfigResolverInterface $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
*/
Comment on lines +32 to +40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* Returns label based on content type.
*
* @param \Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType $contentType
*
* @return string
*
* @throws \Ibexa\AdminUi\Exception\InvalidArgumentException
*/
/**
* @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);

Check failure on line 60 in src/lib/Menu/ContentRightSidebarLabelFactory.php

View workflow job for this annotation

GitHub Actions / Tests (7.4)

Call to method isSatisfiedBy() on an unknown class Ibexa\Dashboard\Specification\ContentTypeIsDashboardContainer.

Check failure on line 60 in src/lib/Menu/ContentRightSidebarLabelFactory.php

View workflow job for this annotation

GitHub Actions / Tests (7.4)

Instantiated class Ibexa\Dashboard\Specification\ContentTypeIsDashboardContainer not found.

Check failure on line 60 in src/lib/Menu/ContentRightSidebarLabelFactory.php

View workflow job for this annotation

GitHub Actions / Tests (8.0)

Call to method isSatisfiedBy() on an unknown class Ibexa\Dashboard\Specification\ContentTypeIsDashboardContainer.

Check failure on line 60 in src/lib/Menu/ContentRightSidebarLabelFactory.php

View workflow job for this annotation

GitHub Actions / Tests (8.0)

Instantiated class Ibexa\Dashboard\Specification\ContentTypeIsDashboardContainer not found.

Check failure on line 60 in src/lib/Menu/ContentRightSidebarLabelFactory.php

View workflow job for this annotation

GitHub Actions / Tests (8.1)

Call to method isSatisfiedBy() on an unknown class Ibexa\Dashboard\Specification\ContentTypeIsDashboardContainer.

Check failure on line 60 in src/lib/Menu/ContentRightSidebarLabelFactory.php

View workflow job for this annotation

GitHub Actions / Tests (8.1)

Instantiated class Ibexa\Dashboard\Specification\ContentTypeIsDashboardContainer not found.
}

/**
* @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');
18 changes: 18 additions & 0 deletions src/lib/Menu/ContentRightSidebarLabelFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are not needed in new code.

Loading