mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-12-11 05:29:30 +00:00
Use ElementTypeNameGenerator where possible
This commit is contained in:
parent
e95197b069
commit
c372109a2f
5 changed files with 37 additions and 60 deletions
|
|
@ -75,17 +75,17 @@ final readonly class ElementTypeNameGenerator
|
|||
|
||||
if ($this->synonymsSettings->isSynonymDefinedForType($type)) {
|
||||
if ($plural) {
|
||||
$syn = $this->synonymsSettings->getSingularSynonymForType($type, $locale);
|
||||
} else {
|
||||
$syn = $this->synonymsSettings->getPluralSynonymForType($type, $locale);
|
||||
} else {
|
||||
$syn = $this->synonymsSettings->getSingularSynonymForType($type, $locale);
|
||||
}
|
||||
|
||||
if ($syn === null) {
|
||||
//Try to fall back to english
|
||||
if ($plural) {
|
||||
$syn = $this->synonymsSettings->getSingularSynonymForType($type, 'en');
|
||||
} else {
|
||||
$syn = $this->synonymsSettings->getPluralSynonymForType($type, 'en');
|
||||
} else {
|
||||
$syn = $this->synonymsSettings->getSingularSynonymForType($type, 'en');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ use App\Entity\UserSystem\Group;
|
|||
use App\Entity\UserSystem\User;
|
||||
use App\Helpers\Trees\TreeViewNode;
|
||||
use App\Services\Cache\UserCacheKeyGenerator;
|
||||
use App\Services\Misc\DataSourceSynonymResolver;
|
||||
use App\Services\ElementTypeNameGenerator;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Contracts\Cache\ItemInterface;
|
||||
|
|
@ -57,7 +57,7 @@ class ToolsTreeBuilder
|
|||
protected TagAwareCacheInterface $cache,
|
||||
protected UserCacheKeyGenerator $keyGenerator,
|
||||
protected Security $security,
|
||||
protected readonly DataSourceSynonymResolver $synonymResolver,
|
||||
private readonly ElementTypeNameGenerator $elementTypeNameGenerator,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -167,90 +167,67 @@ class ToolsTreeBuilder
|
|||
|
||||
if ($this->security->isGranted('read', new AttachmentType())) {
|
||||
$nodes[] = (new TreeViewNode(
|
||||
$this->translator->trans('tree.tools.edit.attachment_types'),
|
||||
$this->elementTypeNameGenerator->typeLabelPlural(AttachmentType::class),
|
||||
$this->urlGenerator->generate('attachment_type_new')
|
||||
))->setIcon('fa-fw fa-treeview fa-solid fa-file-alt');
|
||||
}
|
||||
if ($this->security->isGranted('read', new Category())) {
|
||||
$nodes[] = (new TreeViewNode(
|
||||
$this->synonymResolver->displayNamePlural(
|
||||
'category',
|
||||
'tree.tools.edit.categories',
|
||||
$this->translator->getLocale()
|
||||
),
|
||||
$this->elementTypeNameGenerator->typeLabelPlural(Category::class),
|
||||
$this->urlGenerator->generate('category_new')
|
||||
))->setIcon('fa-fw fa-treeview fa-solid fa-tags');
|
||||
}
|
||||
if ($this->security->isGranted('read', new Project())) {
|
||||
$nodes[] = (new TreeViewNode(
|
||||
$this->synonymResolver->displayNamePlural(
|
||||
'project',
|
||||
'tree.tools.edit.projects',
|
||||
$this->translator->getLocale()),
|
||||
$this->elementTypeNameGenerator->typeLabelPlural(Project::class),
|
||||
$this->urlGenerator->generate('project_new')
|
||||
))->setIcon('fa-fw fa-treeview fa-solid fa-archive');
|
||||
}
|
||||
if ($this->security->isGranted('read', new Supplier())) {
|
||||
$nodes[] = (new TreeViewNode(
|
||||
$this->synonymResolver->displayNamePlural(
|
||||
'supplier',
|
||||
'tree.tools.edit.suppliers',
|
||||
$this->translator->getLocale()
|
||||
),
|
||||
$this->elementTypeNameGenerator->typeLabelPlural(Supplier::class),
|
||||
$this->urlGenerator->generate('supplier_new')
|
||||
))->setIcon('fa-fw fa-treeview fa-solid fa-truck');
|
||||
}
|
||||
if ($this->security->isGranted('read', new Manufacturer())) {
|
||||
$nodes[] = (new TreeViewNode(
|
||||
$this->synonymResolver->displayNamePlural(
|
||||
'manufacturer',
|
||||
'tree.tools.edit.manufacturer',
|
||||
$this->translator->getLocale()
|
||||
),
|
||||
$this->elementTypeNameGenerator->typeLabelPlural(Manufacturer::class),
|
||||
$this->urlGenerator->generate('manufacturer_new')
|
||||
))->setIcon('fa-fw fa-treeview fa-solid fa-industry');
|
||||
}
|
||||
if ($this->security->isGranted('read', new StorageLocation())) {
|
||||
$nodes[] = (new TreeViewNode(
|
||||
$this->synonymResolver->displayNamePlural(
|
||||
'storagelocation',
|
||||
'tree.tools.edit.storelocation',
|
||||
$this->translator->getLocale()
|
||||
),
|
||||
$this->elementTypeNameGenerator->typeLabelPlural(StorageLocation::class),
|
||||
$this->urlGenerator->generate('store_location_new')
|
||||
))->setIcon('fa-fw fa-treeview fa-solid fa-cube');
|
||||
}
|
||||
if ($this->security->isGranted('read', new Footprint())) {
|
||||
$nodes[] = (new TreeViewNode(
|
||||
$this->synonymResolver->displayNamePlural(
|
||||
'footprint',
|
||||
'tree.tools.edit.footprint',
|
||||
$this->translator->getLocale()
|
||||
),
|
||||
$this->elementTypeNameGenerator->typeLabelPlural(Footprint::class),
|
||||
$this->urlGenerator->generate('footprint_new')
|
||||
))->setIcon('fa-fw fa-treeview fa-solid fa-microchip');
|
||||
}
|
||||
if ($this->security->isGranted('read', new Currency())) {
|
||||
$nodes[] = (new TreeViewNode(
|
||||
$this->translator->trans('tree.tools.edit.currency'),
|
||||
$this->elementTypeNameGenerator->typeLabelPlural(Currency::class),
|
||||
$this->urlGenerator->generate('currency_new')
|
||||
))->setIcon('fa-fw fa-treeview fa-solid fa-coins');
|
||||
}
|
||||
if ($this->security->isGranted('read', new MeasurementUnit())) {
|
||||
$nodes[] = (new TreeViewNode(
|
||||
$this->translator->trans('tree.tools.edit.measurement_unit'),
|
||||
$this->elementTypeNameGenerator->typeLabelPlural(MeasurementUnit::class),
|
||||
$this->urlGenerator->generate('measurement_unit_new')
|
||||
))->setIcon('fa-fw fa-treeview fa-solid fa-balance-scale');
|
||||
}
|
||||
if ($this->security->isGranted('read', new LabelProfile())) {
|
||||
$nodes[] = (new TreeViewNode(
|
||||
$this->translator->trans('tree.tools.edit.label_profile'),
|
||||
$this->elementTypeNameGenerator->typeLabelPlural(LabelProfile::class),
|
||||
$this->urlGenerator->generate('label_profile_new')
|
||||
))->setIcon('fa-fw fa-treeview fa-solid fa-qrcode');
|
||||
}
|
||||
if ($this->security->isGranted('read', new PartCustomState())) {
|
||||
$nodes[] = (new TreeViewNode(
|
||||
$this->translator->trans('tree.tools.edit.part_custom_state'),
|
||||
$this->elementTypeNameGenerator->typeLabelPlural(PartCustomState::class),
|
||||
$this->urlGenerator->generate('part_custom_state_new')
|
||||
))->setIcon('fa-fw fa-treeview fa-solid fa-tools');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ use App\Helpers\Trees\TreeViewNodeIterator;
|
|||
use App\Repository\NamedDBElementRepository;
|
||||
use App\Services\Cache\ElementCacheTagGenerator;
|
||||
use App\Services\Cache\UserCacheKeyGenerator;
|
||||
use App\Services\ElementTypeNameGenerator;
|
||||
use App\Services\EntityURLGenerator;
|
||||
use App\Services\Misc\DataSourceSynonymResolver;
|
||||
use App\Settings\BehaviorSettings\SidebarSettings;
|
||||
|
|
@ -67,7 +68,8 @@ class TreeViewGenerator
|
|||
protected TranslatorInterface $translator,
|
||||
private readonly UrlGeneratorInterface $router,
|
||||
private readonly SidebarSettings $sidebarSettings,
|
||||
protected readonly DataSourceSynonymResolver $synonymResolver
|
||||
protected readonly DataSourceSynonymResolver $synonymResolver,
|
||||
private readonly ElementTypeNameGenerator $elementTypeNameGenerator
|
||||
) {
|
||||
$this->rootNodeEnabled = $this->sidebarSettings->rootNodeEnabled;
|
||||
$this->rootNodeExpandedByDefault = $this->sidebarSettings->rootNodeExpanded;
|
||||
|
|
@ -213,17 +215,7 @@ class TreeViewGenerator
|
|||
|
||||
protected function entityClassToRootNodeString(string $class): string
|
||||
{
|
||||
$locale = $this->translator->getLocale();
|
||||
|
||||
return match ($class) {
|
||||
Category::class => $this->synonymResolver->displayNamePlural('category', $locale),
|
||||
StorageLocation::class => $this->synonymResolver->displayNamePlural('storelocation', $locale),
|
||||
Footprint::class => $this->synonymResolver->displayNamePlural('footprint', $locale),
|
||||
Manufacturer::class => $this->synonymResolver->displayNamePlural('manufacturer', $locale),
|
||||
Supplier::class => $this->synonymResolver->displayNamePlural('supplier', $locale),
|
||||
Project::class => $this->synonymResolver->displayNamePlural('project', $locale),
|
||||
default => $this->translator->trans('tree.root_node.text'),
|
||||
};
|
||||
return $this->elementTypeNameGenerator->typeLabelPlural($class);
|
||||
}
|
||||
|
||||
protected function entityClassToRootNodeIcon(string $class): ?string
|
||||
|
|
|
|||
|
|
@ -76,6 +76,8 @@ final class EntityExtension extends AbstractExtension
|
|||
|
||||
/* Gets a human readable label for the type of the given entity */
|
||||
new TwigFunction('entity_type_label', fn(object|string $entity): string => $this->nameGenerator->getLocalizedTypeLabel($entity)),
|
||||
new TwigFunction('type_label', fn(object|string $entity): string => $this->nameGenerator->typeLabel($entity)),
|
||||
new TwigFunction('type_label_p', fn(object|string $entity): string => $this->nameGenerator->typeLabelPlural($entity)),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue