From 7ae84d5a796016ee3cb3a5292466520679143509 Mon Sep 17 00:00:00 2001 From: thomas-sc Date: Tue, 5 Nov 2024 14:36:26 +0100 Subject: [PATCH] select icons in searchresults from avaliable icons in iconpack --- .../ItemTypeIconNameViewHelper.php | 42 +++++++++++++++++++ .../Iconpack/LisztSearchResultsIconpack.yaml | 2 +- Resources/Private/Templates/Search/Index.html | 4 +- .../IconSpritesSearchResults.svg | 4 +- .../{location.svg => place.svg} | 4 +- 5 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 Classes/ViewHelpers/ItemTypeIconNameViewHelper.php rename Resources/Public/Icons/IconPackSearchResults/{location.svg => place.svg} (80%) diff --git a/Classes/ViewHelpers/ItemTypeIconNameViewHelper.php b/Classes/ViewHelpers/ItemTypeIconNameViewHelper.php new file mode 100644 index 0000000..81da14a --- /dev/null +++ b/Classes/ViewHelpers/ItemTypeIconNameViewHelper.php @@ -0,0 +1,42 @@ +registerArgument('iconPackKey', 'string', 'Name of the key for the IconPack (from Iconpack.yaml)', true); + $this->registerArgument('itemType', 'string', 'Name of the itemType (from Zotero)', true); + } + + public static function renderStatic( + array $arguments, + \Closure $renderChildrenClosure, + RenderingContextInterface $renderingContext) + : ?string + { + // get installed icon names from the t3x Iconpack Extension with Key 'lziconsr' as Array + $iconpackFactory = GeneralUtility::makeInstance(IconpackFactory::class); + $iconPackKey = $arguments['iconPackKey']; + $availableIconsArray = $iconpackFactory->queryConfig($iconPackKey, 'icons'); + + // Check if itemType exists as a key in the array + $itemType = $arguments['itemType']; + if (array_key_exists($itemType, $availableIconsArray)) { + return $iconPackKey.','.$itemType; + } + + // else Return default icon + return 'lziconsr,lisztDocument'; + + } +} diff --git a/Configuration/Iconpack/LisztSearchResultsIconpack.yaml b/Configuration/Iconpack/LisztSearchResultsIconpack.yaml index 70dbdfa..e7e06b3 100644 --- a/Configuration/Iconpack/LisztSearchResultsIconpack.yaml +++ b/Configuration/Iconpack/LisztSearchResultsIconpack.yaml @@ -43,7 +43,7 @@ iconpack: - birth - corporation - open-access - - location + - place - person - death - work diff --git a/Resources/Private/Templates/Search/Index.html b/Resources/Private/Templates/Search/Index.html index 89fc34d..bf5c69c 100644 --- a/Resources/Private/Templates/Search/Index.html +++ b/Resources/Private/Templates/Search/Index.html @@ -1,3 +1,4 @@ +{namespace lc=Slub\LisztCommon\ViewHelpers} {key}
+
@@ -49,7 +51,7 @@

{key}

-
+

{hit._source.title}, {hit._source.title}

diff --git a/Resources/Public/Icons/IconPackSearchResults/IconSpritesSearchResults.svg b/Resources/Public/Icons/IconPackSearchResults/IconSpritesSearchResults.svg index 1af5f67..bc088dc 100644 --- a/Resources/Public/Icons/IconPackSearchResults/IconSpritesSearchResults.svg +++ b/Resources/Public/Icons/IconPackSearchResults/IconSpritesSearchResults.svg @@ -117,8 +117,8 @@ - - + + diff --git a/Resources/Public/Icons/IconPackSearchResults/location.svg b/Resources/Public/Icons/IconPackSearchResults/place.svg similarity index 80% rename from Resources/Public/Icons/IconPackSearchResults/location.svg rename to Resources/Public/Icons/IconPackSearchResults/place.svg index 50681de..4470532 100644 --- a/Resources/Public/Icons/IconPackSearchResults/location.svg +++ b/Resources/Public/Icons/IconPackSearchResults/place.svg @@ -1,6 +1,6 @@ - - + +