Skip to content

Commit

Permalink
select icons in searchresults from avaliable icons in iconpack
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-sc committed Nov 5, 2024
1 parent 866f013 commit 7ae84d5
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
42 changes: 42 additions & 0 deletions Classes/ViewHelpers/ItemTypeIconNameViewHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);

namespace Slub\LisztCommon\ViewHelpers;

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

use Quellenform\Iconpack\IconpackFactory;


final class ItemTypeIconNameViewHelper extends AbstractViewHelper
{
public function initializeArguments(): void
{
$this->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';

}
}
2 changes: 1 addition & 1 deletion Configuration/Iconpack/LisztSearchResultsIconpack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ iconpack:
- birth
- corporation
- open-access
- location
- place
- person
- death
- work
4 changes: 3 additions & 1 deletion Resources/Private/Templates/Search/Index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{namespace lc=Slub\LisztCommon\ViewHelpers}
<html
xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:i="http://typo3.org/ns/Quellenform/Iconpack/ViewHelpers"
Expand Down Expand Up @@ -40,6 +41,7 @@ <h4 class="">{key}</h4>
<div class="content grid-colspan-lg-3 grid-colspan-md-2">
<div class="frame">


<f:for each="{searchResults.hits.hits}" as="hit">
<article class="searchresults-item ">
<header>
Expand All @@ -49,7 +51,7 @@ <h4 class="">{key}</h4>
</f:for>
</div>
<div class="searchresults-item-title">
<div class="searchresults-item-icon"><i:icon iconfig="lziconsr,musicSheet" preferredRenderTypes="svgSprite" additionalAttributes="{aria-hidden:'true'}" /></div>
<div class="searchresults-item-icon"><i:icon iconfig="{lc:ItemTypeIconName(iconPackKey: 'lziconsr', itemType: hit._source.itemType)}" preferredRenderTypes="svgSprite" additionalAttributes="{aria-hidden:'true'}" /></div>
<h3 >
{hit._source.title}, {hit._source.title}
</h3>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7ae84d5

Please sign in to comment.