Issues (202)

Classes/Widget/AbstractWidgetController.php (1 issue)

1
<?php
2
namespace ApacheSolrForTypo3\Solr\Widget;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use ApacheSolrForTypo3\Solr\ConnectionManager;
18
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSetService;
19
use ApacheSolrForTypo3\Solr\Search;
20
use ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager;
21
use ApacheSolrForTypo3\Solr\Mvc\Controller\SolrControllerContext;
22
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
23
use ApacheSolrForTypo3\Solr\Util;
24
use ApacheSolrForTypo3\Solr\Widget\WidgetRequest;
25
use TYPO3\CMS\Core\Utility\GeneralUtility;
26
use TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController as CoreAbstractWidgetController;
27
28
/**
29
 * Class AbstractWidgetController
30
 *
31
 * @author Frans Saris <[email protected]>
32
 * @author Timo Hund <[email protected]>
33
 */
34
class AbstractWidgetController extends CoreAbstractWidgetController
35
{
36
37
    /**
38
     * @var array
39
     */
40
    protected $supportedRequestTypes = [WidgetRequest::class];
41
42
    /**
43
     * @var ConfigurationManager
44
     */
45
    private $solrConfigurationManager;
46
47
    /**
48
     * @var \ApacheSolrForTypo3\Solr\Mvc\Controller\SolrControllerContext
49
     */
50
    protected $controllerContext;
51
52
    /**
53
     * @param \ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager
54
     */
55 35
    public function injectSolrConfigurationManager(ConfigurationManager $configurationManager)
56
    {
57 35
        $this->solrConfigurationManager = $configurationManager;
58 35
    }
59
60
    /**
61
     * Initialize the controller context
62
     *
63
     * @return \ApacheSolrForTypo3\Solr\Mvc\Controller\SolrControllerContext ControllerContext to be passed to the view
64
     * @api
65
     */
66 34
    protected function buildControllerContext()
67
    {
68
        /** @var $controllerContext \ApacheSolrForTypo3\Solr\Mvc\Controller\SolrControllerContext */
69 34
        $controllerContext = $this->objectManager->get(SolrControllerContext::class);
0 ignored issues
show
Deprecated Code introduced by
The function TYPO3\CMS\Extbase\Object...ManagerInterface::get() has been deprecated: since TYPO3 10.4, will be removed in version 12.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

69
        $controllerContext = /** @scrutinizer ignore-deprecated */ $this->objectManager->get(SolrControllerContext::class);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
70 34
        $controllerContext->setRequest($this->request);
71 34
        $controllerContext->setResponse($this->response);
72 34
        if ($this->arguments !== null) {
73 34
            $controllerContext->setArguments($this->arguments);
74
        }
75 34
        $controllerContext->setUriBuilder($this->uriBuilder);
76 34
        $typoScriptConfiguration = $this->solrConfigurationManager->getTypoScriptConfiguration();
77 34
        $controllerContext->setTypoScriptConfiguration($typoScriptConfiguration);
78
79 34
        $this->setActiveSearchResultSet($controllerContext);
80
81 34
        return $controllerContext;
82
    }
83
84
    /**
85
     * @param \ApacheSolrForTypo3\Solr\Mvc\Controller\SolrControllerContext $controllerContext
86
     * @return \ApacheSolrForTypo3\Solr\Mvc\Controller\SolrControllerContext
87
     */
88 33
    protected function setActiveSearchResultSet($controllerContext)
89
    {
90 33
        $resultSetService = $this->initializeSearch($controllerContext->getTypoScriptConfiguration());
91 33
        $lastResult = $resultSetService->getLastResultSet();
92 33
        if (!is_null($lastResult)) {
93
            $controllerContext->setSearchResultSet($lastResult);
94
        }
95
96 33
        return $controllerContext;
97
    }
98
99
    /**
100
     * @param TypoScriptConfiguration $typoScriptConfiguration
101
     * @return SearchResultSetService
102
     */
103 33
    protected function initializeSearch(TypoScriptConfiguration $typoScriptConfiguration)
104
    {
105
        /** @var \ApacheSolrForTypo3\Solr\ConnectionManager $solrConnection */
106 33
        $solrConnection = GeneralUtility::makeInstance(ConnectionManager::class)->getConnectionByPageId($GLOBALS['TSFE']->id, Util::getLanguageUid(), $GLOBALS['TSFE']->MP);
107 33
        $search = GeneralUtility::makeInstance(Search::class, /** @scrutinizer ignore-type */ $solrConnection);
108
109 33
        return GeneralUtility::makeInstance(
110
            SearchResultSetService::class,
111
            /** @scrutinizer ignore-type */ $typoScriptConfiguration,
112
            /** @scrutinizer ignore-type */ $search
113
        );
114
    }
115
}
116