Skip to content

Commit

Permalink
[TASK] Replace renderStatic function with render function
Browse files Browse the repository at this point in the history
  • Loading branch information
garbast committed Nov 10, 2024
1 parent aee0607 commit f8b56e3
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 68 deletions.
17 changes: 8 additions & 9 deletions Classes/ViewHelpers/CacheViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,22 @@

use Evoweb\StoreFinder\Domain\Model\Location;
use Evoweb\StoreFinder\Service\CacheService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

class CacheViewHelper extends AbstractViewHelper
{
public function __construct(protected CacheService $cacheService)
{
}

public function initializeArguments(): void
{
$this->registerArgument('location', Location::class, 'the location to tag', true);
}

public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
): void {
$location = $arguments['location'];
GeneralUtility::makeInstance(CacheService::class)->addTagsForPost($location);
public function render(): void
{
$location = $this->arguments['location'];
$this->cacheService->addTagsForPost($location);
}
}
17 changes: 5 additions & 12 deletions Classes/ViewHelpers/Format/BinaryAndViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@

namespace Evoweb\StoreFinder\ViewHelpers\Format;

use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;

class BinaryAndViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;

public function initializeArguments(): void
{
parent::initializeArguments();
Expand All @@ -44,13 +40,10 @@ public function initializeArguments(): void
/**
* Make a binary addition and return the result
*/
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
): int {
$content = $arguments['content'];
$base = $arguments['base'];
return ($content ?: $renderChildrenClosure()) & $base;
public function render(): int
{
$content = $this->arguments['content'];
$base = $this->arguments['base'];
return ($content ?: $this->renderChildren()) & $base;
}
}
10 changes: 3 additions & 7 deletions Classes/ViewHelpers/Format/RemoveEscapingViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

namespace Evoweb\StoreFinder\ViewHelpers\Format;

use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

class RemoveEscapingViewHelper extends AbstractViewHelper
Expand All @@ -30,12 +29,9 @@ public function initializeArguments(): void
/**
* Replace escaping of curly braces
*/
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
): string {
$content = $arguments['content'] ?? $renderChildrenClosure();
public function render(): string
{
$content = $this->arguments['content'] ?? $this->renderChildren();
return str_replace(['\{', '\}'], ['{', '}'], $content);
}
}
15 changes: 4 additions & 11 deletions Classes/ViewHelpers/MinifyViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@

namespace Evoweb\StoreFinder\ViewHelpers;

use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;

class MinifyViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;

/**
* @var bool
*/
Expand All @@ -49,13 +45,10 @@ public function initializeArguments(): void
/**
* Renders the content minified
*/
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
): string {
$content = $arguments['content'];
$content = $content ?: $renderChildrenClosure();
public function render(): string
{
$content = $this->arguments['content'];
$content = $content ?: $this->renderChildren();

/* remove comments */
$content = str_replace('://', "\xff", $content);
Expand Down
61 changes: 32 additions & 29 deletions Classes/ViewHelpers/RecordsViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,59 +16,62 @@
namespace Evoweb\StoreFinder\ViewHelpers;

use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Exception;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;

class RecordsViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;

/**
* ViewHelper returns HTML, thus we need to disable output escaping
*
* @var bool
*/
protected $escapeOutput = false;

public function __construct(protected ConnectionPool $connectionPool)
{
}

public function initializeArguments(): void
{
$this->registerArgument('table', 'string', 'the table for the record icon', true);
$this->registerArgument('uids', 'string', 'list of uids', true);
}

public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
): array {
$table = $arguments['table'];
$uids = is_array($arguments['uids']) ? $arguments['uids'] : GeneralUtility::intExplode(',', $arguments['uids']);
public function render(): array
{
$table = $this->arguments['table'];
$uids = is_array($this->arguments['uids'])
? $this->arguments['uids']
: GeneralUtility::intExplode(',', $this->arguments['uids']);

return self::getRecordsFromTable($table, $uids);
return $this->getRecordsFromTable($table, $uids);
}

protected static function getRecordsFromTable($table, $uids): array
protected function getRecordsFromTable(string $table, array $uids): array
{
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$queryBuilder = $connectionPool->getQueryBuilderForTable($table);
$queryBuilder->getRestrictions()->removeAll();
try {
return $queryBuilder
->select('*')
->from($table)
->where(
$queryBuilder->expr()->in(
'uid',
$queryBuilder->createNamedParameter($uids, ArrayParameterType::INTEGER)
)
$queryBuilder = $this->connectionPool->getQueryBuilderForTable($table);
$queryBuilder
->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class));
$result = $queryBuilder
->select('*')
->from($table)
->where(
$queryBuilder->expr()->in(
'uid',
$queryBuilder->createNamedParameter($uids, ArrayParameterType::INTEGER)
)
->orderBy('uid')
->executeQuery()
->fetchAllAssociative();
} catch (\Exception $e) {
)
->orderBy('uid')
->executeQuery();
try {
return $result->fetchAllAssociative();
} catch (\Exception|Exception $e) {
throw new \RuntimeException(
'Database query failed. Error was: ' . $e->getPrevious()->getMessage(),
1511950673
Expand Down

0 comments on commit f8b56e3

Please sign in to comment.