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] TYPO3 v10 compatibility #2

Open
wants to merge 12 commits into
base: feature/mergeUpstream
Choose a base branch
from
15 changes: 10 additions & 5 deletions Classes/Engine/HandlebarsEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use JFB\Handlebars\HelperRegistry;
use LightnCandy\LightnCandy;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
Expand Down Expand Up @@ -84,16 +85,16 @@ class HandlebarsEngine
*
* @param $settings array
*/
public function __construct($settings)
public function __construct(array $settings)
{
$this->settings = $settings;
$this->settings = $settings ?: [];
$this->extensionKey = $settings['extensionKey'];
$this->controllerName = $settings['controllerName'];
$this->actionName = $settings['actionName'];
$this->templatePath = $settings['templatePath'];
$this->dataProviders = $settings['dataProviders'];
$this->additionalData = $settings['additionalData'];
$this->tempPath = PATH_site . $settings['tempPath'];
$this->dataProviders = $settings['dataProviders'] ?: [];
$this->additionalData = $settings['additionalData'] ?: [];
$this->tempPath = Environment::getPublicPath() . '/' . $settings['tempPath'];
}

/**
Expand Down Expand Up @@ -121,6 +122,10 @@ public function getData()
$data = array_merge_recursive($data, $dataProvider->provide());
}

if (! is_array($this->additionalData)) {
return $data;
}

return array_merge_recursive($data, $this->additionalData);
}

Expand Down
4 changes: 2 additions & 2 deletions Classes/View/HandlebarsView.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
namespace JFB\Handlebars\View;

use TYPO3\CMS\Core\Utility\GeneralUtility;
use JFB\Handlebars\Engine\HandlebarsEngine;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\View\AbstractView;

/***************************************************************
Expand Down Expand Up @@ -63,4 +63,4 @@ protected function getContextVariables()
'actionName' => strtolower($this->controllerContext->getRequest()->getControllerActionName()),
];
}
}
}
34 changes: 25 additions & 9 deletions Classes/ViewHelpers/RenderViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,46 @@
* }" />
* </html>
* </code>
*
*/


class RenderViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
class RenderViewHelper extends \TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper
{
/**
* As this ViewHelper renders HTML, the output must not be escaped.
*
* @var boolean
* @var bool
*/
protected $escapeOutput = false;


public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('template', 'string', 'template path', true);
$this->registerArgument('settings', 'string', 'extension settings', true);
$this->registerArgument('data', 'array', 'Passed data array');
}

/**
* @param string $template
* @param array $settings
* @param array $data
* @return string
*/
public function render($template, array $settings, array $data = []): string
public function render(): string
{
$template = $this->arguments['template'];
$settings = $this->arguments['settings'];
$data = $this->arguments['data'];

/** @var HandlebarsView $handlebarsView */
$handlebarsView = GeneralUtility::makeInstance(HandlebarsView::class);
$handlebarsView->setControllerContext($this->controllerContext);

// @todo fix for TYPO3 v8 can be removed later
if ($this->controllerContext !== null) {
$controllerContext = $this->controllerContext;
} elseif (method_exists($this->renderingContext, 'getControllerContext')) {
$controllerContext = $this->renderingContext->getControllerContext();
}
$handlebarsView->setControllerContext($controllerContext);

if (
isset($settings['handlebars'])
Expand All @@ -83,7 +99,7 @@ public function render($template, array $settings, array $data = []): string
} else {
$settings = [];
}

$settings = array_merge_recursive($settings, [
'dataProviders' => [
LabelDataProvider::class,
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
},
"require": {
"php": "^7.0",
"typo3/cms-core": "^8.7.13|| ^9.5.0",
"typo3/cms-core": "^8.7.13 || ^9.5.17 || ^10.4.10",
"zordius/lightncandy": "^1.2",
"sinso/translationapi": "^2.0.0"
"visol/translationapi": "^2.0.0"
},
"require-dev": {
}
Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
'constraints' => [
'depends' => [
'php' => '7.0.0-0.0.0',
'typo3' => '7.6.*-9.5.99',
'typo3' => '8.7.13-10.9.99',
'extbase' => '',
],
'conflicts' => [
Expand Down
4 changes: 2 additions & 2 deletions ext_tables.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
if (!defined('TYPO3_MODE')) {
die ('Access denied.');
die('Access denied.');
}

TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile('handlebars', 'Configuration/TypoScript', 'TS skeleton');
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile('handlebars', 'Configuration/TypoScript', 'TS skeleton');