Skip to content

Commit

Permalink
Create search bar plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Richter committed Oct 16, 2024
1 parent bb7e349 commit 35855fd
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 3 deletions.
7 changes: 6 additions & 1 deletion Classes/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,18 @@ public function indexAction(array $searchParams = []): ResponseInterface

$this->view->assign('totalItems', $elasticResponse['hits']['total']['value']);

$searchParams = $this->request->getQueryParams();
$searchParams = $this->request->getQueryParams();
$this->view->assign('searchParams', $searchParams);


$this->view->assign('searchResults', $elasticResponse);
return $this->htmlResponse();
}

public function searchBarAction(): ResponseInterface
{
return $this->htmlResponse();
}


}
40 changes: 40 additions & 0 deletions Configuration/TCA/Overrides/tt_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
'Liszt Search Results'
);

// register search Bar Plugin
ExtensionUtility::registerPlugin(
'liszt_common',
'SearchBar',
'Liszt Search Bar'
);

// Adds the content element to the "Type" dropdown
ExtensionManagementUtility::addTcaSelectItem(
Expand All @@ -27,6 +33,19 @@
]
);

// Adds the content element to the "Type" dropdown
ExtensionManagementUtility::addTcaSelectItem(
'tt_content',
'CType',
[
'label' => 'LLL:EXT:liszt_common/Resources/Private/Language/locallang.xlf:searchbar_title',
'value' => 'lisztcommon_searchbar',
'icon' => 'content-text',
'group' => 'plugins',
'description' => 'LLL:EXT:liszt_common/Resources/Private/Language/locallang.xlf:searchbar_description'
]
);

// configure the backend form fields for SearchList Plugin (no extra fields needed)
$GLOBALS['TCA']['tt_content']['types']['lisztcommon_searchlisting'] = [
'showitem' => '
Expand All @@ -47,3 +66,24 @@
]
]
];

// configure the backend form fields for SearchBar Plugin (no extra fields needed)
$GLOBALS['TCA']['tt_content']['types']['lisztcommon_searchbar'] = [
'showitem' => '
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,
--palette--;;general,
header; Title,
bodytext;LLL:EXT:core/Resources/Private/Language/Form/locallang_ttc.xlf:bodytext_formlabel,
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access,
--palette--;;hidden,
--palette--;;acces,
',
'columnsOverrides' => [
'bodytext' => [
'config' => [
'enableRichtext' => true,
'richtextConfiguration' => 'default'
]
]
]
];
10 changes: 10 additions & 0 deletions Configuration/TsConfig/page.tsconfig
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,18 @@ mod.wizards.newContentElement.wizardItems {
list_type = lisztcommon_searchlisting
}
}
lisztcommon_searchbar {
iconIdentifier = content-text
title = LLL:EXT:liszt_common/Resources/Private/Language/locallang.xlf:searchbar_title
description = LLL:EXT:liszt_common/Resources/Private/Language/locallang.xlf:searchbar_description
tt_content_defValues {
CType = list
list_type = lisztcommon_searchbar
}
}
}
show := addToList(lisztcommon_searchlisting)
show := addToList(lisztcommon_searchbar)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Language/de.locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<source>Auflistung der Suchergebnisse</source>
</trans-unit>
<trans-unit id="searchbar_title" >
<source>Liszt SearchBar</source>
<source>Liszt Suchschlitz</source>
</trans-unit>
<trans-unit id="searchbar_description" >
<source>Sucheingabe / Suchschlitz</source>
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<source>Auflistung der Suchergebnisse</source>
</trans-unit>
<trans-unit id="searchbar_title" >
<source>Liszt SearchBar</source>
<source>Liszt Suchschlitz</source>
</trans-unit>
<trans-unit id="searchbar_description" >
<source>Sucheingabe / Suchschlitz</source>
Expand Down
21 changes: 21 additions & 0 deletions Resources/Private/Templates/Search/SearchBar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{namespace lw=Slub\LisztCommon\ViewHelpers}
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">


<f:comment>ToDo: viewHelper for SearchParams</f:comment>
<section id="content" class="searchbar">
<f:debug>{_all}</f:debug>
<div class="container-xl">

<f:form name="searchBar" controller="Search" action="index" method="get" extensionName="liszt_common" class="form-inline">
<div class="input-group mb-3">

<f:form.textfield name="searchParams[searchText]" value="{searchParams.tx_liszt_common_searchlisting.searchParams.searchText}" class="form-control no-shadow" aria="{label:'Text input with dropdown button'}" placeholder="" />
<f:form.button class="btn btn-outline-dark" id="button-searchBar">{f:translate(key: 'searchButtonLabel', extensionName: 'liszt_common')}</f:form.button>
</div>
</f:form>


</div>
</section>
</html>
8 changes: 8 additions & 0 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
[ SearchController::class => 'index' ]
);

// configure Search Listing Plugin, disable caching so that the search terms entered are updated and not the entire search-page was cached in page cache
ExtensionUtility::configurePlugin(
'LisztCommon',
'SearchBar',
[ SearchController::class => 'searchBar' ],
[ ]
);

ExtensionManagementUtility::addPageTSConfig(
'<INCLUDE_TYPOSCRIPT: source="FILE:EXT:liszt_common/Configuration/TsConfig/page.tsconfig">'
);

0 comments on commit 35855fd

Please sign in to comment.