Skip to content
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
41 changes: 21 additions & 20 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
* text=auto
/.ddev export-ignore
/.github export-ignore
/Build export-ignore
/Tests export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php-cs-fixer.php export-ignore
/composer.lock export-ignore
/docker-compose.yml export-ignore
/packaging_exclude.php export-ignore
/phpstan.neon export-ignore
/phpstan-baseline.neon export-ignore
/phpunit.functional.xml export-ignore
/phpunit.unit.xml export-ignore
/rector.php export-ignore
/renovate.json export-ignore
/typoscript-lint.yml export-ignore
/version-bumper.yaml export-ignore
* text=auto
/.ddev export-ignore
/.github export-ignore
/Build export-ignore
/Tests export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php-cs-fixer.php export-ignore
/composer.lock export-ignore
/composer-dependency-analyser.php export-ignore
/docker-compose.yml export-ignore
/packaging_exclude.php export-ignore
/phpstan.neon export-ignore
/phpstan-baseline.neon export-ignore
/phpunit.functional.xml export-ignore
/phpunit.unit.xml export-ignore
/rector.php export-ignore
/renovate.json export-ignore
/typoscript-lint.yml export-ignore
/version-bumper.yaml export-ignore
72 changes: 72 additions & 0 deletions Classes/ContentObject/CanUpdateRegister.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare(strict_types=1);

/*
* This file is part of the TYPO3 CMS extension "handlebars_forms".
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

namespace CPSIT\Typo3HandlebarsForms\ContentObject;

use Psr\Http\Message;
use TYPO3\CMS\Core;
use TYPO3\CMS\Frontend;

/**
* CanUpdateRegister
*
* @author Elias Häußler <e.haeussler@familie-redlich.de>
* @license GPL-2.0-or-later
* @internal
*
* @property Message\ServerRequestInterface $request
*/
trait CanUpdateRegister
{
protected Core\Information\Typo3Version $typo3Version;

protected function updateRegister(string $key, ?int $value = null): void
{
match ($this->typo3Version->getMajorVersion()) {
13 => $this->modifyRegisterUsingTsfe($key, $value),
14 => $this->modifyRegisterUsingRequest($key, $value),
default => null,
};
}

/**
* @todo Remove once support for TYPO3 v13 is dropped
*/
protected function modifyRegisterUsingTsfe(string $key, ?int $value): void
{
$tsfe = $this->getTypoScriptFrontendController();

if ($value === null) {
unset($tsfe->register[$key]);
} else {
$tsfe->register[$key] = $value;
}
}

protected function modifyRegisterUsingRequest(string $key, ?int $value): void
{
$stack = $this->request->getAttribute('frontend.register.stack');

if (!($stack instanceof Frontend\ContentObject\RegisterStack)) {
return;
}

if ($value !== null) {
$stack->current()->set($key, $value);
}
}
}
20 changes: 13 additions & 7 deletions Classes/ContentObject/ChildrenContentObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use CPSIT\Typo3HandlebarsForms\Domain;
use Symfony\Component\DependencyInjection;
use TYPO3\CMS\Core;

/**
* ChildrenContentObject
Expand All @@ -29,9 +30,16 @@
#[DependencyInjection\Attribute\AutoconfigureTag('frontend.contentobject', ['identifier' => 'HBS_CHILDREN'])]
final class ChildrenContentObject extends AbstractHandlebarsFormsContentObject
{
use CanUpdateRegister;

private const IDENTIFIER_COUNT = 'HBS_CHILDREN_COUNT';
private const IDENTIFIER_CURRENT = 'HBS_CHILDREN_CURRENT';

public function __construct()
{
$this->typo3Version = new Core\Information\Typo3Version();
}

/**
* @return list<mixed>|null
*/
Expand All @@ -49,23 +57,21 @@ protected function resolve(array $configuration, Context\ValueResolutionContext

$processedValue = [];

// Add children count to TSFE register
// @todo Use $this->request->getAttribute('frontend.register.stack') in TYPO3 v14
$tsfe = $this->getTypoScriptFrontendController();
$tsfe->register[self::IDENTIFIER_COUNT] = count($children);
// Add children count to register
$this->updateRegister(self::IDENTIFIER_COUNT, count($children));

foreach ($children as $index => $childViewModel) {
// Add current child index to TSFE register
$tsfe->register[self::IDENTIFIER_CURRENT] = $index;
$this->updateRegister(self::IDENTIFIER_CURRENT, count($children));

try {
$processedValue[] = $context->process($configuration, viewModel: $childViewModel);
} finally {
unset($tsfe->register[self::IDENTIFIER_CURRENT]);
$this->updateRegister(self::IDENTIFIER_CURRENT);
}
}

unset($tsfe->register[self::IDENTIFIER_COUNT]);
$this->updateRegister(self::IDENTIFIER_COUNT);

return $processedValue;
}
Expand Down
17 changes: 10 additions & 7 deletions Classes/ContentObject/RenderablesContentObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use CPSIT\Typo3HandlebarsForms\Domain;
use Symfony\Component\DependencyInjection;
use TYPO3\CMS\Core;
use TYPO3\CMS\Fluid;
use TYPO3\CMS\Form;

Expand All @@ -31,6 +32,8 @@
#[DependencyInjection\Attribute\AutoconfigureTag('frontend.contentobject', ['identifier' => 'HBS_RENDERABLES'])]
final class RenderablesContentObject extends AbstractHandlebarsFormsContentObject
{
use CanUpdateRegister;

private const IDENTIFIER_COUNT = 'HBS_RENDERABLES_COUNT';
private const IDENTIFIER_CURRENT = 'HBS_RENDERABLES_CURRENT';

Expand All @@ -42,7 +45,9 @@ public function __construct(
private readonly iterable $viewModelBuilders,
private readonly Context\ContextStack $contextStack,
private readonly Context\ValueCollector $valueCollector,
) {}
) {
$this->typo3Version = new Core\Information\Typo3Version();
}

/**
* @return list<mixed>
Expand Down Expand Up @@ -99,17 +104,15 @@ protected function resolve(array $configuration, Context\ValueResolutionContext
}

// Add renderables count to TSFE register
// @todo Use $this->request->getAttribute('frontend.register.stack') in TYPO3 v14
$tsfe = $this->getTypoScriptFrontendController();
$tsfe->register[self::IDENTIFIER_COUNT] = count($renderables);
$this->updateRegister(self::IDENTIFIER_COUNT, count($renderables));

foreach ($renderables as $index => $child) {
if (!$this->isEnabled($child)) {
continue;
}

// Add current renderable index to TSFE register
$tsfe->register[self::IDENTIFIER_CURRENT] = $index;
$this->updateRegister(self::IDENTIFIER_CURRENT, $index);

try {
if (array_key_exists($child->getType() . '.', $configuration)) {
Expand Down Expand Up @@ -145,11 +148,11 @@ protected function resolve(array $configuration, Context\ValueResolutionContext
$processedRenderables[] = $processedChild;
}
} finally {
unset($tsfe->register[self::IDENTIFIER_CURRENT]);
$this->updateRegister(self::IDENTIFIER_CURRENT);
}
}

unset($tsfe->register[self::IDENTIFIER_COUNT]);
$this->updateRegister(self::IDENTIFIER_COUNT);

return $processedRenderables;
}
Expand Down
11 changes: 5 additions & 6 deletions Classes/Domain/Renderer/HandlebarsFormRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace CPSIT\Typo3HandlebarsForms\Domain\Renderer;

use CPSIT\Typo3Handlebars\View;
use Psr\EventDispatcher;
use Symfony\Component\DependencyInjection;
use TYPO3\CMS\Core;
use TYPO3\CMS\Extbase;
Expand All @@ -39,6 +40,7 @@ public function __construct(
private readonly Extbase\Configuration\ConfigurationManagerInterface $configurationManager,
private readonly View\HandlebarsViewFactory $viewFactory,
private readonly Core\TypoScript\TypoScriptService $typoScriptService,
private readonly EventDispatcher\EventDispatcherInterface $eventDispatcher,
) {
$this->typo3Version = new Core\Information\Typo3Version();
}
Expand Down Expand Up @@ -172,13 +174,10 @@ private function triggerBeforeRenderingHook(): void
}
}

/**
* @todo Enable once support for TYPO3 v14 is added
*/
private function triggerBeforeRenderableIsRenderedEvent(): void
{
// $this->eventDispatcher->dispatch(
// new Form\Event\BeforeRenderableIsRenderedEvent($this->formRuntime->getFormDefinition(), $this->formRuntime),
// );
$this->eventDispatcher->dispatch(
new Form\Event\BeforeRenderableIsRenderedEvent($this->formRuntime->getFormDefinition(), $this->formRuntime),
);
}
}
2 changes: 1 addition & 1 deletion Documentation/Installation/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Requirements
============

- PHP 8.2 - 8.5
- TYPO3 13.4 LTS
- TYPO3 13.4 LTS - 14.3 LTS

.. _steps:

Expand Down
2 changes: 1 addition & 1 deletion Documentation/Introduction/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Features
- Ability to define generic form rendering definitions
- Possibility to override form rendering for specific form definitions
- Easy to extend and customize for custom form elements
- Compatible with TYPO3 13.4 LTS
- Compatible with TYPO3 13.4 LTS and 14.3 LTS

.. _support:

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ configured using dedicated interface implementations.
* Ability to define generic form rendering definitions
* Possibility to override form rendering for specific form definitions
* Easy to extend and customize for custom form elements
* Compatible with TYPO3 13.4 LTS
* Compatible with TYPO3 13.4 LTS and 14.3 LTS

## 🔥 Installation

Expand Down
34 changes: 34 additions & 0 deletions composer-dependency-analyser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

/*
* This file is part of the TYPO3 CMS extension "handlebars_forms".
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

use ShipMonk\ComposerDependencyAnalyser;
use TYPO3\CMS\Form;
use TYPO3\CMS\Frontend;

$configuration = new ComposerDependencyAnalyser\Config\Configuration();
$configuration
->addPathToScan('Classes', false)
->addPathToScan('Configuration', false)
->addPathToScan('Tests', true)
->ignoreUnknownClasses([
// @todo Remove once support for TYPO3 v13 is dropped
Form\Event\BeforeRenderableIsRenderedEvent::class,
Frontend\ContentObject\RegisterStack::class,
])
;

return $configuration;
21 changes: 11 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@
"ext-libxml": "*",
"cpsit/typo3-handlebars": "^1.0@alpha",
"devtheorem/php-handlebars": "^2.0",
"psr/event-dispatcher": "^1.0",
"psr/http-message": "^1.0 || ^2.0",
"psr/log": "^3.0",
"symfony/dependency-injection": "^7.0",
"typo3/cms-core": "~13.4.0",
"typo3/cms-extbase": "~13.4.0",
"typo3/cms-fluid": "~13.4.0",
"typo3/cms-form": "~13.4.0",
"typo3/cms-frontend": "~13.4.0",
"typo3fluid/fluid": "^4.0"
"typo3/cms-core": "~13.4.0 || ~14.3.0",
"typo3/cms-extbase": "~13.4.0 || ~14.3.0",
"typo3/cms-fluid": "~13.4.0 || ~14.3.0",
"typo3/cms-form": "~13.4.0 || ~14.3.0",
"typo3/cms-frontend": "~13.4.0 || ~14.3.0",
"typo3fluid/fluid": "^4.0 || ^5.0"
},
"require-dev": {
"armin/editorconfig-cli": "^2.0",
Expand All @@ -42,13 +43,13 @@
"phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpcov": "^10.0 || ^11.0 || ^12.0 || ^13.0",
"phpunit/phpunit": "^11.5 || ^12.5 || ^13.0",
"saschaegerer/phpstan-typo3": "^2.1",
"saschaegerer/phpstan-typo3": "^2.1 || ^3.0",
"shipmonk/composer-dependency-analyser": "^1.8",
"ssch/typo3-rector": "^3.11",
"typo3/cms-install": "~13.4.0",
"typo3/cms-tstemplate": "~13.4.0",
"typo3/cms-install": "~13.4.0 || ~14.3.0",
"typo3/cms-tstemplate": "~13.4.0 || ~14.3.0",
"typo3/coding-standards": "^0.8.0",
"typo3/testing-framework": "^9.3.0"
"typo3/testing-framework": "^9.5.0"
},
"repositories": [
{
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packaging_exclude.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
'files' => [
'DS_Store',
'composer.lock',
'composer-dependency-analyser.php',
'docker-compose.yml',
'editorconfig',
'gitattributes',
Expand Down
Loading
Loading