From: Marcel Werk Date: Thu, 27 Apr 2023 16:06:18 +0000 (+0200) Subject: Custom icon for search result items (#5461) X-Git-Tag: 6.0.0_Alpha_1~183 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=191dbdfd0652fa9231e2583dbc7accd9d8315e2e;p=GitHub%2FWoltLab%2FWCF.git Custom icon for search result items (#5461) Closes #5109 --- diff --git a/com.woltlab.wcf/templates/searchResultList.tpl b/com.woltlab.wcf/templates/searchResultList.tpl index d8c6aa06b1..33c6b438c6 100644 --- a/com.woltlab.wcf/templates/searchResultList.tpl +++ b/com.woltlab.wcf/templates/searchResultList.tpl @@ -3,7 +3,9 @@ {foreach from=$objects item=message}
  • - {if $message->getUserProfile()} + {if $customIcons[$message->getObjectTypeName()]|isset} + {icon size=48 name=$customIcons[$message->getObjectTypeName()]} + {elseif $message->getUserProfile()} {user object=$message->getUserProfile() type='avatar48' ariaHidden='true' tabindex='-1'} {else} {icon size=48 name='file'} diff --git a/wcfsetup/install/files/lib/data/search/SearchAction.class.php b/wcfsetup/install/files/lib/data/search/SearchAction.class.php index 2e4dd99f5a..f21357cfcb 100644 --- a/wcfsetup/install/files/lib/data/search/SearchAction.class.php +++ b/wcfsetup/install/files/lib/data/search/SearchAction.class.php @@ -120,6 +120,7 @@ class SearchAction extends AbstractDatabaseObjectAction WCF::getTPL()->assign([ 'objects' => $resultHandler->getSearchResults(), 'query' => $resultHandler->getQuery(), + 'customIcons' => $resultHandler->getCustomIcons(), ]); return [ @@ -166,6 +167,7 @@ class SearchAction extends AbstractDatabaseObjectAction WCF::getTPL()->assign([ 'objects' => $resultHandler->getSearchResults(), 'query' => $resultHandler->getQuery(), + 'customIcons' => $resultHandler->getCustomIcons(), ]); return [ diff --git a/wcfsetup/install/files/lib/system/search/AbstractSearchProvider.class.php b/wcfsetup/install/files/lib/system/search/AbstractSearchProvider.class.php index 421e1b1d54..4577bbbecc 100644 --- a/wcfsetup/install/files/lib/system/search/AbstractSearchProvider.class.php +++ b/wcfsetup/install/files/lib/system/search/AbstractSearchProvider.class.php @@ -120,6 +120,14 @@ abstract class AbstractSearchProvider extends AbstractObjectTypeProcessor implem return ''; } + /** + * @inheritDoc + */ + public function getCustomIconName(): ?string + { + return null; + } + /** * @deprecated 5.5 */ diff --git a/wcfsetup/install/files/lib/system/search/ISearchProvider.class.php b/wcfsetup/install/files/lib/system/search/ISearchProvider.class.php index fd71b44222..1a1c3f8fec 100644 --- a/wcfsetup/install/files/lib/system/search/ISearchProvider.class.php +++ b/wcfsetup/install/files/lib/system/search/ISearchProvider.class.php @@ -102,4 +102,11 @@ interface ISearchProvider * placeholder {WCF_SEARCH_INNER_JOIN} within an empty INNER JOIN() statement. */ public function getFetchObjectsQuery(?PreparedStatementConditionBuilder $additionalConditions = null): string; + + /** + * Provides the ability to show a custom icon in the list of search results. + * Returns either a FontAwesome icon name or null. The latter will trigger the default behavior. + * @since 6.0 + */ + public function getCustomIconName(): ?string; } diff --git a/wcfsetup/install/files/lib/system/search/SearchResultHandler.class.php b/wcfsetup/install/files/lib/system/search/SearchResultHandler.class.php index 6507e05504..bbd3b601ed 100644 --- a/wcfsetup/install/files/lib/system/search/SearchResultHandler.class.php +++ b/wcfsetup/install/files/lib/system/search/SearchResultHandler.class.php @@ -138,6 +138,21 @@ final class SearchResultHandler return $this->getLegacyTemplateName(); } + /** + * @return array + */ + public function getCustomIcons(): array + { + $customIcons = []; + foreach (SearchEngine::getInstance()->getAvailableObjectTypes() as $name => $type) { + if ($type instanceof ISearchProvider) { + $customIcons[$name] = $type->getCustomIconName(); + } + } + + return $customIcons; + } + /** * Will be removed with 6.0 once all search providers have switched to ISearchProvider. * @deprecated 5.5