Skip to content

Commit

Permalink
[TASK] migrate to typo3fluid/fluid v4 as required by TYPO3 13
Browse files Browse the repository at this point in the history
  • Loading branch information
dkd-kaehm committed Sep 16, 2024
1 parent 1eb01bf commit 4ea023c
Show file tree
Hide file tree
Showing 27 changed files with 188 additions and 279 deletions.
11 changes: 3 additions & 8 deletions Classes/ViewHelpers/Debug/DocumentScoreAnalyzerViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet;
use ApacheSolrForTypo3\Solr\Domain\Search\Score\ScoreCalculationService;
use ApacheSolrForTypo3\Solr\ViewHelpers\AbstractSolrFrontendViewHelper;
use Closure;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;

/**
* Class DocumentScoreAnalyzerViewHelper
Expand All @@ -36,8 +33,6 @@
*/
class DocumentScoreAnalyzerViewHelper extends AbstractSolrFrontendViewHelper
{
use CompileWithRenderStatic;

protected static ?ScoreCalculationService $scoreService = null;

protected $escapeOutput = false;
Expand All @@ -55,7 +50,7 @@ public function initializeArguments(): void
* @throws AspectNotFoundException
* @noinspection PhpMissingReturnTypeInspection
*/
public static function renderStatic(array $arguments, Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
public function render()
{
$content = '';
// only check whether a BE user is logged in, don't need to check
Expand All @@ -65,10 +60,10 @@ public static function renderStatic(array $arguments, Closure $renderChildrenClo
return $content;
}

$document = $arguments['document'];
$document = $this->arguments['document'];

/** @var SearchResultSet $resultSet */
$resultSet = self::getUsedSearchResultSetFromRenderingContext($renderingContext);
$resultSet = self::getUsedSearchResultSetFromRenderingContext($this->renderingContext);
$debugData = '';
if (
$resultSet->getUsedSearch()->getDebugResponse() !== null
Expand Down
20 changes: 6 additions & 14 deletions Classes/ViewHelpers/Debug/QueryViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@
namespace ApacheSolrForTypo3\Solr\ViewHelpers\Debug;

use ApacheSolrForTypo3\Solr\ViewHelpers\AbstractSolrFrontendViewHelper;
use Closure;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;

/**
* Class QueryViewHelper
Expand All @@ -31,8 +28,6 @@
*/
class QueryViewHelper extends AbstractSolrFrontendViewHelper
{
use CompileWithRenderStatic;

/**
* @inheritdoc
*/
Expand All @@ -44,13 +39,10 @@ class QueryViewHelper extends AbstractSolrFrontendViewHelper
* @throws AspectNotFoundException
* @noinspection PhpUnused
*/
public static function renderStatic(
array $arguments,
Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext,
) {
public function render()
{
$content = '';
$resultSet = self::getUsedSearchResultSetFromRenderingContext($renderingContext);
$resultSet = self::getUsedSearchResultSetFromRenderingContext($this->renderingContext);
$backendUserIsLoggedIn = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('backend.user', 'isLoggedIn');
if (
$backendUserIsLoggedIn === true
Expand All @@ -60,9 +52,9 @@ public static function renderStatic(
&& $resultSet->getUsedSearch()->getDebugResponse() !== null
&& !empty($resultSet->getUsedSearch()->getDebugResponse()->parsedquery)
) {
$renderingContext->getVariableProvider()->add('parsedQuery', $resultSet->getUsedSearch()->getDebugResponse()->parsedquery);
$content = $renderChildrenClosure();
$renderingContext->getVariableProvider()->remove('parsedQuery');
$this->renderingContext->getVariableProvider()->add('parsedQuery', $resultSet->getUsedSearch()->getDebugResponse()->parsedquery);
$content = $this->renderChildren();
$this->renderingContext->getVariableProvider()->remove('parsedQuery');

if ($content === null) {
$content = '<br><strong>Parsed Query:</strong><br>' . htmlspecialchars($resultSet->getUsedSearch()->getDebugResponse()->parsedquery);
Expand Down
18 changes: 5 additions & 13 deletions Classes/ViewHelpers/Document/HighlightResultViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,13 @@
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Result\SearchResult;
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet;
use ApacheSolrForTypo3\Solr\ViewHelpers\AbstractSolrFrontendViewHelper;
use Closure;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;

/**
* Class HighlightResultViewHelper
*/
class HighlightResultViewHelper extends AbstractSolrFrontendViewHelper
{
use CompileWithRenderStatic;

protected $escapeOutput = false;

/**
Expand All @@ -45,15 +40,12 @@ public function initializeArguments(): void
$this->registerArgument('fieldName', 'string', 'The fieldName', true);
}

public static function renderStatic(
array $arguments,
Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
): string {
public function render(): string
{
/** @var SearchResultSet $resultSet */
$resultSet = $arguments['resultSet'];
$fieldName = $arguments['fieldName'];
$document = $arguments['document'];
$resultSet = $this->arguments['resultSet'];
$fieldName = $this->arguments['fieldName'];
$document = $this->arguments['document'];
$highlightedContent = self::getHighlightedContent($resultSet, $document, $fieldName);
if (is_string($highlightedContent)) {
return self::escapeEverythingExceptAllowedTags($resultSet, $highlightedContent);
Expand Down
18 changes: 5 additions & 13 deletions Classes/ViewHelpers/Document/RelevanceViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,12 @@
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Result\SearchResult;
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet;
use ApacheSolrForTypo3\Solr\ViewHelpers\AbstractSolrFrontendViewHelper;
use Closure;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;

/**
* Class RelevanceViewHelper
*/
class RelevanceViewHelper extends AbstractSolrFrontendViewHelper
{
use CompileWithRenderStatic;

/**
* @inheritDoc
*/
Expand All @@ -48,18 +43,15 @@ public function initializeArguments(): void
* @noinspection PhpMissingReturnTypeInspection
* @noinspection PhpUnused
*/
public static function renderStatic(
array $arguments,
Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext,
) {
public function render()
{
/** @var SearchResult $document */
$document = $arguments['document'];
$document = $this->arguments['document'];

/** @var SearchResultSet $resultSet */
$resultSet = $arguments['resultSet'];
$resultSet = $this->arguments['resultSet'];

$maximumScore = $arguments['maximumScore'] ?? $resultSet->getMaximumScore();
$maximumScore = $this->arguments['maximumScore'] ?? $resultSet->getMaximumScore();
$content = 0;

if ($maximumScore <= 0) {
Expand Down
20 changes: 6 additions & 14 deletions Classes/ViewHelpers/Facet/Area/GroupViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,12 @@

use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\FacetCollection;
use ApacheSolrForTypo3\Solr\ViewHelpers\AbstractSolrFrontendViewHelper;
use Closure;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;

/**
* Class GroupViewHelper
*/
class GroupViewHelper extends AbstractSolrFrontendViewHelper
{
use CompileWithRenderStatic;

/**
* @inheritdoc
*/
Expand All @@ -46,19 +41,16 @@ public function initializeArguments(): void
/**
* Renders group
*/
public static function renderStatic(
array $arguments,
Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext,
) {
public function render()
{
/** @var FacetCollection $facets */
$facets = $arguments['facets'];
$requiredGroup = $arguments['groupName'] ?? 'main';
$facets = $this->arguments['facets'];
$requiredGroup = $this->arguments['groupName'] ?? 'main';
$filtered = $facets->getByGroupName($requiredGroup);

$templateVariableProvider = $renderingContext->getVariableProvider();
$templateVariableProvider = $this->renderingContext->getVariableProvider();
$templateVariableProvider->add('areaFacets', $filtered);
$content = $renderChildrenClosure();
$content = $this->renderChildren();
$templateVariableProvider->remove('areaFacets');

return $content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,12 @@

use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionBased\OptionCollection;
use ApacheSolrForTypo3\Solr\ViewHelpers\AbstractSolrFrontendViewHelper;
use Closure;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;

/**
* Class LabelFilterViewHelper
*/
class LabelFilterViewHelper extends AbstractSolrFrontendViewHelper
{
use CompileWithRenderStatic;

protected $escapeOutput = false;

/**
Expand All @@ -43,19 +38,16 @@ public function initializeArguments(): void
/**
* Renders group label filter
*/
public static function renderStatic(
array $arguments,
Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext,
) {
public function render()
{
/** @var OptionCollection $options */
$options = $arguments['options'];
$requiredPrefix = mb_strtolower($arguments['prefix'] ?? '');
$options = $this->arguments['options'];
$requiredPrefix = mb_strtolower($this->arguments['prefix'] ?? '');
$filtered = $options->getByLowercaseLabelPrefix($requiredPrefix);

$templateVariableProvider = $renderingContext->getVariableProvider();
$templateVariableProvider = $this->renderingContext->getVariableProvider();
$templateVariableProvider->add('filteredOptions', $filtered);
$content = $renderChildrenClosure();
$content = $this->renderChildren();
$templateVariableProvider->remove('filteredOptions');

return $content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,12 @@

use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionBased\OptionCollection;
use ApacheSolrForTypo3\Solr\ViewHelpers\AbstractSolrFrontendViewHelper;
use Closure;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;

/**
* Class LabelPrefixesViewHelper
*/
class LabelPrefixesViewHelper extends AbstractSolrFrontendViewHelper
{
use CompileWithRenderStatic;

protected $escapeOutput = false;

/**
Expand All @@ -46,22 +41,19 @@ public function initializeArguments(): void
/**
* @noinspection PhpMissingReturnTypeInspection
*/
public static function renderStatic(
array $arguments,
Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
public function render()
{
/** @var OptionCollection $options */
$options = $arguments['options'];
$length = $arguments['length'] ?? 1;
$sortBy = $arguments['sortBy'] ?? 'count';
$options = $this->arguments['options'];
$length = $this->arguments['length'] ?? 1;
$sortBy = $this->arguments['sortBy'] ?? 'count';
$prefixes = $options->getLowercaseLabelPrefixes($length);

$prefixes = static::applySortBy($prefixes, $sortBy);

$templateVariableProvider = $renderingContext->getVariableProvider();
$templateVariableProvider = $this->renderingContext->getVariableProvider();
$templateVariableProvider->add('prefixes', $prefixes);
$content = $renderChildrenClosure();
$content = $this->renderChildren();
$templateVariableProvider->remove('prefixes');

return $content;
Expand Down
17 changes: 6 additions & 11 deletions Classes/ViewHelpers/FrequentlySearchedViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
use ApacheSolrForTypo3\Solr\Domain\Search\FrequentSearches\FrequentSearchesService;
use ApacheSolrForTypo3\Solr\Exception as SolrException;
use ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager;
use Closure;
use Doctrine\DBAL\Exception as DBALException;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException as AspectNotFoundExceptionAlias;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;

/**
* Class LastSearchesViewHelper
Expand All @@ -55,11 +53,8 @@ class FrequentlySearchedViewHelper extends AbstractSolrViewHelper
* @throws DBALException
* @throws SolrException
*/
public static function renderStatic(
array $arguments,
Closure $renderChildrenClosure,
RenderingContextInterface|RenderingContext $renderingContext
) {
public function render()
{
$cache = self::getInitializedCache();
/** @var ConfigurationManager $configurationManager */
$configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
Expand All @@ -71,20 +66,20 @@ public static function renderStatic(
$cache,
);

if (!$renderingContext instanceof RenderingContext) {
if (!$this->renderingContext instanceof RenderingContext) {
throw new SolrException(
'Solr rendering context must be an instance of RenderingContext',
1717760054,
);
}

$frequentSearches = $frequentSearchesService->getFrequentSearchTerms($renderingContext->getRequest());
$frequentSearches = $frequentSearchesService->getFrequentSearchTerms($this->renderingContext->getRequest());
$minimumSize = $typoScriptConfiguration->getSearchFrequentSearchesMinSize();
$maximumSize = $typoScriptConfiguration->getSearchFrequentSearchesMaxSize();

$templateVariableContainer = $renderingContext->getVariableProvider();
$templateVariableContainer = $this->renderingContext->getVariableProvider();
$templateVariableContainer->add('frequentSearches', self::enrichFrequentSearchesInfo($frequentSearches, $minimumSize, $maximumSize));
$output = $renderChildrenClosure();
$output = $this->renderChildren();
$templateVariableContainer->remove('frequentSearches');
return $output;
}
Expand Down
Loading

0 comments on commit 4ea023c

Please sign in to comment.