Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] Avoid Fluid compile trait #2200

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading