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] apply v11 improvements & remove deprecations #496

Merged
merged 2 commits into from
Oct 24, 2022
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
5 changes: 3 additions & 2 deletions Classes/DataProcessing/RootSiteProcessing/SiteProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FriendsOfTYPO3\Headless\DataProcessing\RootSiteProcessing;

use Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\Driver\Result;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
Expand Down Expand Up @@ -159,7 +160,7 @@ private function filterSites(array $allowedSites = []): array
/**
* @param int $pid
* @return array<int>
* @throws \Doctrine\DBAL\Driver\Exception
* @throws Exception
*/
private function fetchAvailableRootSitesByPid(int $pid): array
{
Expand Down Expand Up @@ -191,7 +192,7 @@ private function fetchAvailableRootSitesByPid(int $pid): array
* @param array<Site> $sites
* @param array<string, mixed> $config
* @return array<int, array>
* @throws \Doctrine\DBAL\Driver\Exception
* @throws Exception
*/
private function fetchPageData(array $sites, array $config = []): array
{
Expand Down
3 changes: 2 additions & 1 deletion Classes/Form/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace FriendsOfTYPO3\Headless\Form;

use FriendsOfTYPO3\Headless\Form\Service\FormTranslationService;
use TYPO3\CMS\Core\Utility\GeneralUtility;

use function array_keys;
use function array_merge;
Expand All @@ -24,7 +25,7 @@ class Translator

public function __construct(FormTranslationService $service = null)
{
$this->translator = $service ?? FormTranslationService::getInstance();
$this->translator = $service ?? GeneralUtility::makeInstance(FormTranslationService::class);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Classes/Service/PaginationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PaginationService
];

/**
* @var \TYPO3\CMS\Extbase\Persistence\QueryResultInterface
* @var QueryResultInterface
*/
protected $objects;

Expand Down
7 changes: 5 additions & 2 deletions Classes/ViewHelpers/Form/RegisterFieldViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@

namespace FriendsOfTYPO3\Headless\ViewHelpers\Form;

use TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;

/**
* Registers field for generating hidden fields
*
* @codeCoverageIgnore
*/
class RegisterFieldViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper
class RegisterFieldViewHelper extends AbstractFormFieldViewHelper
{
/**
* Initialize the arguments.
*
* @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
* @throws Exception
*/
public function initializeArguments()
{
Expand Down
9 changes: 3 additions & 6 deletions Classes/ViewHelpers/Format/Json/DecodeViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,25 @@ class DecodeViewHelper extends AbstractViewHelper
*/
public function initializeArguments(): void
{
$this->registerArgument('json', 'string', 'json to decode', false, '');
$this->registerArgument('json', 'string', 'json to decode', false);
}

/**
* @param string $json
* @return mixed
*/
public function render($json = null)
public function render()
{
$json = $this->arguments['json'];
if ($json === null) {
$json = $this->renderChildren();
if (empty($json)) {
return null;
}
}

$object = json_decode($json, true);

if (json_last_error() === JSON_ERROR_NONE) {
return $object;
}

if ($GLOBALS['TYPO3_CONF_VARS']['FE']['debug'] ?? false) {
throw new \Exception(sprintf(
'Failure "%s" occured when running json_decode() for string: %s',
Expand Down
22 changes: 10 additions & 12 deletions Classes/ViewHelpers/LoginFormViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@

namespace FriendsOfTYPO3\Headless\ViewHelpers;

use TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
use TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy;
use TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper;

/**
* Form ViewHelper. Generates a :html:`<form>` Tag.
Expand Down Expand Up @@ -49,7 +52,7 @@
*
* @codeCoverageIgnore
*/
class LoginFormViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper
class LoginFormViewHelper extends FormViewHelper
{
/**
* @var array
Expand Down Expand Up @@ -125,11 +128,6 @@ protected function setFormActionUri()
->setArgumentsToBeExcludedFromQueryString(isset($this->arguments['argumentsToBeExcludedFromQueryString']) ? (array)$this->arguments['argumentsToBeExcludedFromQueryString'] : [])
->setFormat($this->arguments['format'] ?? '');

$addQueryStringMethod = $this->arguments['addQueryStringMethod'] ?? null;
if (is_string($addQueryStringMethod)) {
$uriBuilder->setAddQueryStringMethod($addQueryStringMethod);
}

$pageUid = (int)($this->arguments['pageUid'] ?? 0);
if ($pageUid > 0) {
$uriBuilder->setTargetPageUid($pageUid);
Expand All @@ -154,8 +152,8 @@ protected function setFormActionUri()
*/
protected function renderAdditionalIdentityFields()
{
if ($this->viewHelperVariableContainer->exists(\TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'additionalIdentityProperties')) {
$additionalIdentityProperties = $this->viewHelperVariableContainer->get(\TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'additionalIdentityProperties');
if ($this->viewHelperVariableContainer->exists(FormViewHelper::class, 'additionalIdentityProperties')) {
$additionalIdentityProperties = $this->viewHelperVariableContainer->get(FormViewHelper::class, 'additionalIdentityProperties');
$output = '';
foreach ($additionalIdentityProperties as $identity) {
$this->addHiddenField('identity', $identity);
Expand Down Expand Up @@ -208,7 +206,7 @@ protected function renderHiddenReferrerFields()
protected function addFieldNamePrefixToViewHelperVariableContainer()
{
$fieldNamePrefix = $this->getFieldNamePrefix();
$this->viewHelperVariableContainer->add(\TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'fieldNamePrefix', $fieldNamePrefix);
$this->viewHelperVariableContainer->add(FormViewHelper::class, 'fieldNamePrefix', $fieldNamePrefix);
}

/**
Expand All @@ -222,11 +220,11 @@ protected function addFieldNamePrefixToViewHelperVariableContainer()
*/
protected function renderHiddenIdentityField($object, $name)
{
if ($object instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
if ($object instanceof LazyLoadingProxy) {
$object = $object->_loadRealInstance();
}
if (!is_object($object)
|| !($object instanceof \TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject)
|| !($object instanceof AbstractDomainObject)
|| ($object->_isNew() && !$object->_isClone())
) {
return '';
Expand All @@ -250,7 +248,7 @@ protected function renderTrustedPropertiesField()
{
$formFieldNames
= $this->viewHelperVariableContainer->get(
\TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class,
FormViewHelper::class,
'formFieldNames'
);
$requestHash
Expand Down
5 changes: 3 additions & 2 deletions Classes/XClass/Controller/FormFrontendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Error\Error;
use TYPO3\CMS\Extbase\Security\Cryptography\HashService;
use TYPO3\CMS\Form\Domain\Factory\ArrayFormFactory;
use TYPO3\CMS\Form\Domain\Model\FormDefinition;
Expand Down Expand Up @@ -209,7 +210,7 @@ public function renderAction(): ResponseInterface
$this->getControllerContext()->getRequest()->getMethod() === 'POST') {
$result = $formRuntime->getRequest()->getOriginalRequestMappingResults();
/**
* @var array<string,\TYPO3\CMS\Extbase\Error\Error[]>
* @var array<string, Error[]>
*/
$errors = $result->getFlattenedErrors();
$formStatus['status'] = $result->hasErrors() ? 'failure' : 'success';
Expand All @@ -231,7 +232,7 @@ public function renderAction(): ResponseInterface
}

/**
* @param array<string,\TYPO3\CMS\Extbase\Error\Error[]> $errors
* @param array<string, Error[]> $errors
* @param string $formIdentifier
* @return array<string, string>|null
*/
Expand Down
3 changes: 2 additions & 1 deletion Classes/XClass/ResourceLocalDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
use FriendsOfTYPO3\Headless\Utility\UrlUtility;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Http\ApplicationType;
use TYPO3\CMS\Core\Resource\Driver\LocalDriver;
use TYPO3\CMS\Core\Resource\ResourceStorage;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* @codeCoverageIgnore
*/
class ResourceLocalDriver extends \TYPO3\CMS\Core\Resource\Driver\LocalDriver
class ResourceLocalDriver extends LocalDriver
{
protected function determineBaseUrl(): void
{
Expand Down
17 changes: 12 additions & 5 deletions Configuration/RequestMiddlewares.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@
* LICENSE.md file that was distributed with this source code.
*/

use FriendsOfTYPO3\Headless\Middleware\ElementBodyResponseMiddleware;
use FriendsOfTYPO3\Headless\Middleware\RedirectHandler;
use FriendsOfTYPO3\Headless\Middleware\ShortcutAndMountPointRedirect;
use FriendsOfTYPO3\Headless\Middleware\UserIntMiddleware;
use TYPO3\CMS\Core\Configuration\Features;
use TYPO3\CMS\Core\Utility\GeneralUtility;

return (static function (): array {
$features = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\Features::class);
$features = GeneralUtility::makeInstance(Features::class);

$middlewares = [
'frontend' => [
'headless/cms-frontend/prepare-user-int' => [
'after' => [
'typo3/cms-frontend/content-length-headers',
],
'target' => \FriendsOfTYPO3\Headless\Middleware\UserIntMiddleware::class
'target' => UserIntMiddleware::class
],
],
];
Expand All @@ -26,7 +33,7 @@
'after' => [
'typo3/cms-adminpanel/data-persister',
],
'target' => \FriendsOfTYPO3\Headless\Middleware\ElementBodyResponseMiddleware::class
'target' => ElementBodyResponseMiddleware::class
];
}

Expand All @@ -45,7 +52,7 @@
'disabled' => true
],
'headless/cms-redirects/redirecthandler' => [
'target' => \FriendsOfTYPO3\Headless\Middleware\RedirectHandler::class,
'target' => RedirectHandler::class,
'before' => [
$rearrangedMiddlewares ? 'typo3/cms-frontend/base-redirect-resolver' : 'typo3/cms-frontend/page-resolver',
],
Expand All @@ -54,7 +61,7 @@
],
],
'headless/cms-frontend/shortcut-and-mountpoint-redirect' => [
'target' => \FriendsOfTYPO3\Headless\Middleware\ShortcutAndMountPointRedirect::class,
'target' => ShortcutAndMountPointRedirect::class,
'after' => [
'typo3/cms-frontend/prepare-tsfe-rendering',
],
Expand Down
10 changes: 6 additions & 4 deletions Configuration/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
*/

declare(strict_types=1);

use FriendsOfTYPO3\Headless\Seo\XmlSitemap\XmlSitemapRenderer;
use FriendsOfTYPO3\Headless\Utility\HeadlessFrontendUrlInterface;
use FriendsOfTYPO3\Headless\Utility\UrlUtility;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use TYPO3\CMS\Form\Controller\FormFrontendController;
use TYPO3\CMS\FrontendLogin\Controller\LoginController;

return static function (ContainerConfigurator $configurator): void {
$services = $configurator->services()
Expand All @@ -24,15 +26,15 @@

$excludes = ['../Classes/Seo/XmlSitemap/XmlSitemapRenderer.php'];

if (!class_exists(\TYPO3\CMS\Form\Controller\FormFrontendController::class, false)) {
if (!class_exists(FormFrontendController::class, false)) {
$excludes = array_merge($excludes, [
'../Classes/Form/*',
'../Classes/XClass/Controller/FormFrontendController.php',
'../Classes/XClass/FormRuntime.php',
]);
}

if (!class_exists(\TYPO3\CMS\FrontendLogin\Controller\LoginController::class, false)) {
if (!class_exists(LoginController::class, false)) {
$excludes = array_merge($excludes, [
'../Classes/XClass/Controller/LoginController.php',
]);
Expand All @@ -41,5 +43,5 @@
$toLoad->exclude($excludes);

$services->set(HeadlessFrontendUrlInterface::class, UrlUtility::class)->autowire(false);
$services->set(FriendsOfTYPO3\Headless\Seo\XmlSitemap\XmlSitemapRenderer::class)->public()->share(false);
$services->set(XmlSitemapRenderer::class)->public()->share(false);
};
5 changes: 4 additions & 1 deletion Configuration/SiteConfiguration/Overrides/site.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
* LICENSE.md file that was distributed with this source code.
*/

$features = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\Features::class);
use TYPO3\CMS\Core\Configuration\Features;
use TYPO3\CMS\Core\Utility\GeneralUtility;

$features = GeneralUtility::makeInstance(Features::class);

if ($features->isFeatureEnabled('headless.frontendUrls')) {
$tempColumns = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
* LICENSE.md file that was distributed with this source code.
*/

$features = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\Features::class);
use TYPO3\CMS\Core\Configuration\Features;
use TYPO3\CMS\Core\Utility\GeneralUtility;

$features = GeneralUtility::makeInstance(Features::class);

if ($features->isFeatureEnabled('headless.frontendUrls')) {
$tempColumns = [
Expand Down
8 changes: 5 additions & 3 deletions Configuration/TCA/Overrides/sys_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@
* LICENSE.md file that was distributed with this source code.
*/

defined('TYPO3_MODE') || die();
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;

defined('TYPO3') || die();

call_user_func(static function () {
/**
* Default TypoScript for Headless
*/
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile(
ExtensionManagementUtility::addStaticFile(
'headless',
'Configuration/TypoScript',
'Headless'
);
/**
* 2.x JSON response
*/
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile(
ExtensionManagementUtility::addStaticFile(
'headless',
'Configuration/TypoScript/2.x',
'Headless - 2.x JSON response'
Expand Down
3 changes: 2 additions & 1 deletion Tests/Functional/ContentTypes/DefaultContentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
*/

declare(strict_types=1);
use FriendsOfTYPO3\Headless\Test\Functional\ContentTypes\BaseContentTypeTest;

use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;

class DefaultContentsTest extends \FriendsOfTYPO3\Headless\Test\Functional\ContentTypes\BaseContentTypeTest
class DefaultContentsTest extends BaseContentTypeTest
{
public function testContentStructure()
{
Expand Down
1 change: 0 additions & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
'author_email' => 'extensions@macopedia.pl',
'author_company' => 'Macopedia Sp. z o.o.',
'category' => 'fe',
'internal' => '',
'version' => '3.1.2',
'constraints' => [
'depends' => [
Expand Down
Loading