Skip to content

Commit

Permalink
[TASK] Avoid Fluid compile trait
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessCoder committed Dec 9, 2024
1 parent 8610fcd commit 3c1c58c
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 22 deletions.
8 changes: 8 additions & 0 deletions Classes/ViewHelpers/AbstractFormViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ abstract class AbstractFormViewHelper extends AbstractViewHelper
const SCOPE_VARIABLE_CONTAINER = 'container';
const SCOPE_VARIABLE_GRIDS = 'grids';

/**
* @return string
*/
public function render()
{
return static::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext);
}

protected function callRenderMethod(): string
{
return static::renderStatic(
Expand Down
11 changes: 8 additions & 3 deletions Classes/ViewHelpers/Content/GetViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;

/**
* Gets all child content of a record based on area.
Expand Down Expand Up @@ -55,8 +54,6 @@
*/
class GetViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;

/**
* @var boolean
*/
Expand Down Expand Up @@ -88,6 +85,14 @@ public function initializeArguments(): void
$this->registerArgument('hideUntranslated', 'boolean', 'Exclude untranslated records', false, false);
}

/**
* @return array|string|null
*/
public function render()
{
return static::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext);
}

/**
* @return string|array|null
*/
Expand Down
2 changes: 1 addition & 1 deletion Classes/ViewHelpers/Content/RenderViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static function renderStatic(
RenderingContextInterface $renderingContext
) {
$content = parent::renderStatic($arguments, $renderChildrenClosure, $renderingContext);
if (true === is_array($content)) {
if (is_array($content)) {
return implode(PHP_EOL, $content);
}
return $content;
Expand Down
14 changes: 10 additions & 4 deletions Classes/ViewHelpers/Form/DataViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;

/**
* Converts raw flexform xml into an associative array, and applies any
Expand Down Expand Up @@ -47,8 +46,6 @@
*/
class DataViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;

/**
* @var boolean
*/
Expand All @@ -68,7 +65,15 @@ public function initializeArguments(): void
}

/**
* @return mixed
* @return array
*/
public function render()
{
return self::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext);
}

/**
* @return array
*/
public static function renderStatic(
array $arguments,
Expand Down Expand Up @@ -117,6 +122,7 @@ public static function renderStatic(
1387049117
);
}
/** @var array $dataArray */
$dataArray = HookHandler::trigger(
HookHandler::FORM_DATA_FETCHED,
[
Expand Down
13 changes: 10 additions & 3 deletions Classes/ViewHelpers/Form/OptionViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@
use FluidTYPO3\Flux\Form\OptionCarryingInterface;
use FluidTYPO3\Flux\ViewHelpers\AbstractFormViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;

/**
* Form option ViewHelper
*/
class OptionViewHelper extends AbstractFormViewHelper
{
use CompileWithContentArgumentAndRenderStatic;

public static string $option = '';

public function initializeArguments(): void
Expand All @@ -29,6 +26,11 @@ public function initializeArguments(): void
$this->registerArgument('name', 'string', 'Name of the option to be set', true);
}

public function render()
{
return self::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext);
}

public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
Expand All @@ -54,4 +56,9 @@ public static function renderStatic(
1602693000
);
}

public function getContentArgumentName(): ?string
{
return 'value';
}
}
11 changes: 8 additions & 3 deletions Classes/ViewHelpers/Form/RenderViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
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;

/**
* ## Main form rendering ViewHelper
Expand All @@ -24,8 +23,6 @@
*/
class RenderViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;

/**
* @var boolean
*/
Expand All @@ -36,6 +33,14 @@ public function initializeArguments(): void
$this->registerArgument('form', Form::class, 'Form instance to render as HTML', true);
}

/**
* @return string
*/
public function render()
{
return self::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext);
}

public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
Expand Down
15 changes: 11 additions & 4 deletions Classes/ViewHelpers/Form/VariableViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@

use FluidTYPO3\Flux\ViewHelpers\AbstractFormViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;

/**
* Sets an option in the Form instance
*/
class VariableViewHelper extends AbstractFormViewHelper
{
use CompileWithContentArgumentAndRenderStatic;

public function initializeArguments(): void
{
$this->registerArgument('value', 'mixed', 'Value of the option');
Expand All @@ -32,6 +29,11 @@ public function initializeArguments(): void
);
}

public function render()
{
return self::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext);
}

public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
Expand All @@ -40,7 +42,12 @@ public static function renderStatic(
/** @var string $variableName */
$variableName = $arguments['name'];
static::getContainerFromRenderingContext($renderingContext)
->setVariable($variableName, $renderChildrenClosure());
->setVariable($variableName, $arguments['value'] ?? $renderChildrenClosure());
return '';
}

public function getContentArgumentName(): ?string
{
return 'value';
}
}
18 changes: 14 additions & 4 deletions Classes/ViewHelpers/InlineViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use TYPO3Fluid\Fluid\Core\Parser\Source;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;

/**
* Inline Fluid rendering ViewHelper
Expand All @@ -37,8 +36,6 @@
*/
class InlineViewHelper extends AbstractViewHelper
{
use CompileWithContentArgumentAndRenderStatic;

/**
* @var boolean
*/
Expand All @@ -59,6 +56,14 @@ public function initializeArguments(): void
);
}

/**
* @return mixed
*/
public function render()
{
return self::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext);
}

/**
* @return mixed
*/
Expand All @@ -67,10 +72,15 @@ public static function renderStatic(
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
$source = $renderChildrenClosure();
$source = (string) ($arguments['code'] ?? $renderChildrenClosure());
return $renderingContext->getTemplateParser()
->parse(class_exists(Source::class) ? new Source($source) : $source)
->getRootNode()
->evaluate($renderingContext);
}

public function getContentArgumentName(): ?string
{
return 'code';
}
}
4 changes: 4 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#1 \\$templateString of method TYPO3Fluid\\\\Fluid\\\\Core\\\\Parser\\\\TemplateParser\\:\\:parse\\(\\) expects string, string\\|TYPO3Fluid\\\\Fluid\\\\Core\\\\Parser\\\\Source given\\.$#"
count: 1
path: Classes/ViewHelpers/InlineViewHelper.php
-
message: "#^Call to an undefined method Doctrine\\\\DBAL\\\\Result\\:\\:fetch(All)?\\(\\)\\.$#"
count: 2
Expand Down

0 comments on commit 3c1c58c

Please sign in to comment.