3131
3232namespace VuFind \View \Helper \Root ;
3333
34- use Laminas \ Http \ Request ;
35- use Laminas \ View \ Helper \ Url ;
34+ use Psr \ Log \ LoggerAwareInterface ;
35+ use VuFind \ Log \ LoggerAwareTrait ;
3636use VuFind \Search \Base \Results ;
3737use VuFind \Search \Results \PluginManager ;
3838use VuFind \Search \SearchTabsHelper ;
3939use VuFind \Search \UrlQueryHelper ;
40+ use VuFind \ServiceManager \Factory \Autowire ;
4041
4142/**
4243 * "Search tabs" view helper
4849 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
4950 * @link https://vufind.org/wiki/development Wiki
5051 */
51- class SearchTabs extends \ Laminas \ View \ Helper \AbstractHelper implements \ Psr \ Log \ LoggerAwareInterface
52+ class SearchTabs implements LoggerAwareInterface
5253{
53- use \VuFind \Log \LoggerAwareTrait;
54-
55- /**
56- * Search manager
57- *
58- * @var PluginManager
59- */
60- protected $ results ;
61-
62- /**
63- * Request
64- *
65- * @var Request
66- */
67- protected $ request ;
68-
69- /**
70- * Url
71- *
72- * @var Url
73- */
74- protected $ url ;
75-
76- /**
77- * Search tab helper
78- *
79- * @var SearchTabsHelper
80- */
81- protected $ helper ;
54+ use LoggerAwareTrait;
8255
8356 /**
8457 * Cached hidden filter url params
@@ -97,18 +70,29 @@ class SearchTabs extends \Laminas\View\Helper\AbstractHelper implements \Psr\Log
9770 /**
9871 * Constructor
9972 *
100- * @param PluginManager $results Search results plugin manager
101- * @param Url $url URL helper
102- * @param SearchTabsHelper $helper Search tabs helper
73+ * @param PluginManager $results Search results plugin manager
74+ * @param Url $url URL helper
75+ * @param SearchTabsHelper $helper Search tabs helper
76+ * @param SearchMemory $searchMemory Search memory view helper
10377 */
10478 public function __construct (
105- PluginManager $ results ,
106- Url $ url ,
107- SearchTabsHelper $ helper
79+ protected PluginManager $ results ,
80+ #[Autowire(container: 'ViewHelperManager ' )]
81+ protected Url $ url ,
82+ protected SearchTabsHelper $ helper ,
83+ #[Autowire(container: 'ViewHelperManager ' )]
84+ protected SearchMemory $ searchMemory
10885 ) {
109- $ this ->results = $ results ;
110- $ this ->url = $ url ;
111- $ this ->helper = $ helper ;
86+ }
87+
88+ /**
89+ * Invoke the helper.
90+ *
91+ * @return static
92+ */
93+ public function __invoke (): static
94+ {
95+ return $ this ;
11296 }
11397
11498 /**
@@ -135,18 +119,15 @@ public function getTabConfig(
135119 $ allSettings = $ this ->helper ->getSettings ();
136120 $ retVal ['showCounts ' ] = $ allSettings ['show_result_counts ' ] ?? false ;
137121 foreach ($ this ->helper ->getTabConfig () as $ key => $ label ) {
138- $ permissionName = null ;
139- if (isset ($ allPermissions [$ key ])) {
140- $ permissionName = $ allPermissions [$ key ];
141- }
122+ $ permissionName = $ allPermissions [$ key ] ?? null ;
142123 $ class = $ this ->helper ->extractClassName ($ key );
143124 $ filters = isset ($ allFilters [$ key ]) ? (array )$ allFilters [$ key ] : [];
144- $ selected = $ class == $ activeSearchClass && $ this ->helper ->filtersMatch ($ class , $ hiddenFilters , $ filters );
125+ $ selected = $ class == $ activeSearchClass
126+ && $ this ->helper ->filtersMatch ($ class , $ hiddenFilters , $ filters );
145127 try {
146128 if ($ type == 'basic ' ) {
147129 if (!isset ($ activeOptions )) {
148- $ activeOptions
149- = $ this ->results ->get ($ activeSearchClass )->getOptions ();
130+ $ activeOptions = $ this ->results ->get ($ activeSearchClass )->getOptions ();
150131 }
151132 $ url = $ this ->remapBasicSearch (
152133 $ activeOptions ,
@@ -262,14 +243,12 @@ public function getCurrentHiddenFilterParams(
262243 return '' ;
263244 }
264245 if (!isset ($ this ->cachedHiddenFilterParams [$ searchClassId ])) {
265- $ view = $ this ->getView ();
266246 $ hiddenFilters = $ this ->getHiddenFilters (
267247 $ searchClassId ,
268248 $ ignoreHiddenFilterMemory
269249 );
270250 if (empty ($ hiddenFilters ) && !$ ignoreHiddenFilterMemory ) {
271- $ hiddenFilters = $ view ->plugin ('searchMemory ' )
272- ->getLastHiddenFilters ($ searchClassId );
251+ $ hiddenFilters = $ this ->searchMemory ->getLastHiddenFilters ($ searchClassId );
273252 if (empty ($ hiddenFilters )) {
274253 $ hiddenFilters = $ this ->getHiddenFilters ($ searchClassId );
275254 }
@@ -323,15 +302,14 @@ protected function remapBasicSearch(
323302 foreach ($ filters as $ filter ) {
324303 $ params ->addHiddenFilter ($ filter );
325304 }
326-
327305 // Find matching handler for new query (and use default if no match):
328306 $ options = $ results ->getOptions ();
329307 $ targetHandler = $ options ->getHandlerForLabel (
330308 $ activeOptions ->getLabelForBasicHandler ($ handler )
331309 );
332310
333311 // Build new URL:
334- $ results -> getParams () ->setBasicSearch ($ query , $ targetHandler );
312+ $ params ->setBasicSearch ($ query , $ targetHandler );
335313 return ($ this ->url )($ options ->getSearchAction ())
336314 . $ results ->getUrlQuery ()->getParams (false );
337315 }
@@ -346,12 +324,9 @@ protected function remapBasicSearch(
346324 */
347325 protected function getHomeTabUrl ($ class , $ filters )
348326 {
349- // If an advanced search is available, link there; otherwise, just go
350- // to the search home:
351327 $ results = $ this ->results ->get ($ class );
352- $ url = ($ this ->url )($ results ->getOptions ()->getSearchHomeAction ())
328+ return ($ this ->url )($ results ->getOptions ()->getSearchHomeAction ())
353329 . $ this ->buildUrlHiddenFilters ($ results , $ filters );
354- return $ url ;
355330 }
356331
357332 /**
0 commit comments