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-7800: Removed Sub-items tab for non-containers without children #1189

Draft
wants to merge 2 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
1 change: 0 additions & 1 deletion src/lib/Component/TabsComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
foreach ($tabGroupEvent->getData()->getTabs() as $tab) {
$tabEvent = $this->dispatchTabPreRenderEvent($tab, $parameters);
$parameters = array_merge($parameters, $tabGroupEvent->getParameters(), $tabEvent->getParameters());
$tabs[] = $this->composeTabParameters($tabEvent->getData(), $parameters);
}

return $this->twig->render(
Expand All @@ -84,7 +83,7 @@
return $tabEvent;
}

private function composeTabParameters(TabInterface $tab, array $parameters): array

Check failure on line 86 in src/lib/Component/TabsComponent.php

View workflow job for this annotation

GitHub Actions / Tests (8.3)

Method Ibexa\AdminUi\Component\TabsComponent::composeTabParameters() is unused.
{
return [
'name' => $tab->getName(),
Expand Down
33 changes: 32 additions & 1 deletion src/lib/Tab/LocationView/SubItemsTab.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,29 @@
namespace Ibexa\AdminUi\Tab\LocationView;

use Ibexa\Contracts\AdminUi\Tab\AbstractEventDispatchingTab;
use Ibexa\Contracts\AdminUi\Tab\ConditionalTabInterface;
use Ibexa\Contracts\AdminUi\Tab\OrderedTabInterface;
use Ibexa\Contracts\Core\Repository\LocationService;
use JMS\TranslationBundle\Annotation\Desc;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;

class SubItemsTab extends AbstractEventDispatchingTab implements OrderedTabInterface
class SubItemsTab extends AbstractEventDispatchingTab implements OrderedTabInterface, ConditionalTabInterface
{
private LocationService $locationService;

public function __construct(
Environment $twig,
TranslatorInterface $translator,
EventDispatcherInterface $eventDispatcher,
LocationService $locationService
) {
parent::__construct($twig, $translator, $eventDispatcher);

$this->locationService = $locationService;
}

public const URI_FRAGMENT = 'ibexa-tab-location-view-sub-items';

public function getIdentifier(): string
Expand All @@ -37,6 +55,19 @@ public function getTemplate(): string
return '@ibexadesign/content/tab/sub_items.html.twig';
}

public function evaluate(array $parameters): bool
{
/** @var \Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType $contentType */
$contentType = $parameters['contentType'];

/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Location $location */
$location = $parameters['location'];

$hasChildren = $this->locationService->getLocationChildCount($location) > 0;

return $contentType->isContainer && !$hasChildren;
}

public function getTemplateParameters(array $contextParameters = []): array
{
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Content $content */
Expand Down
Loading