Skip to content

Commit

Permalink
TASK: The contentsCss in v12 is now trasnformed to array (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbelasichon committed May 15, 2023
1 parent 1a0c935 commit 8dba6b9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 65 deletions.
44 changes: 14 additions & 30 deletions Classes/Form/FormDataProvider/RichtextEncoreConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,17 @@
use Ssch\Typo3Encore\Asset\EntrypointLookupCollectionInterface;
use Ssch\Typo3Encore\Asset\EntrypointLookupInterface;
use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;

final class RichtextEncoreConfiguration implements FormDataProviderInterface
{
private EntrypointLookupCollectionInterface $entrypointLookupCollection;

private int $majorVersion = 12;

public function __construct(
EntrypointLookupCollectionInterface $entrypointLookupCollection = null,
Typo3Version $typo3Version = null
) {
public function __construct(EntrypointLookupCollectionInterface $entrypointLookupCollection = null)
{
$this->entrypointLookupCollection = $entrypointLookupCollection ?? GeneralUtility::makeInstance(
EntrypointLookupCollection::class
);
$typo3Version = $typo3Version ?? GeneralUtility::makeInstance(Typo3Version::class);
$this->majorVersion = $typo3Version->getMajorVersion();
}

public function addData(array $result): array
Expand All @@ -52,32 +45,26 @@ public function addData(array $result): array
if (! isset($rteConfiguration['editor']['config']['contentsCss'])) {
continue;
}
$contentsCss = $rteConfiguration['editor']['config']['contentsCss'];

if (is_array($contentsCss) && $this->majorVersion < 12) {
$updatedContentCss = [];
foreach ($contentsCss as $cssFile) {
$updatedContent = $this->getContentCss($cssFile);
$updatedContentCss[] = is_array($updatedContent) ? $updatedContent : [$updatedContent];
}
$contentsCss = array_merge(...$updatedContentCss);
} elseif (is_string($contentsCss)) {
$contentsCss = $this->getContentCss($contentsCss);
$contentsCss = (array) $rteConfiguration['editor']['config']['contentsCss'];

$updatedContentCss = [];
foreach ($contentsCss as $cssFile) {
$updatedContent = $this->getContentCss($cssFile);
$updatedContentCss[] = is_array($updatedContent) ? $updatedContent : [$updatedContent];
}
$contentsCss = array_merge(...$updatedContentCss);

$result['processedTca']['columns'][$fieldName]['config']['richtextConfiguration']['editor']['config']['contentsCss'] = $contentsCss;
}

return $result;
}

/**
* @return array|string
*/
private function getContentCss(string $contentsCss)
private function getContentCss(string $contentsCss): array
{
if (! str_starts_with($contentsCss, 'typo3_encore:')) {
// keep the css file as-is
return ($this->majorVersion < 12) ? [$contentsCss] : $contentsCss;
return [$contentsCss];
}

// strip prefix
Expand All @@ -96,10 +83,7 @@ private function getContentCss(string $contentsCss)
// call reset() to allow multiple RTEs on the same page.
// Otherwise only the first RTE will have the CSS.
$entryPointLookup->reset();
if ($this->majorVersion < 12) {
return $cssFiles;
}
// TYPO3 12 support only one css file. See https://forge.typo3.org/issues/99327
return reset($cssFiles);

return $cssFiles;
}
}
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
"minimum-stability": "dev",
"require": {
"php": ">=7.4",
"typo3/cms-core": "^10.4.2 || ^11.5 || ^12",
"typo3/cms-core": "^10.4.2 || ^11.5 || ^12.4",
"symfony/web-link": "^5.4 || ^6",
"symfony/asset": "^5.0 || ^6",
"ext-dom": "*",
"typo3/cms-tstemplate": "^10.4.2 || ^11.2 || ^12",
"typo3/cms-tstemplate": "^10.4.2 || ^11.5 || ^12.4",
"webmozart/assert": "^1.10"
},
"require-dev": {
"phpstan/phpstan": "^1.0",
"typo3/testing-framework": "^6.2 || dev-main",
"typo3/minimal": "^10.4 || ^11.5 || ^12.0",
"typo3/minimal": "^10.4 || ^11.5 || ^12.4",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpspec/prophecy-phpunit": "^2.0",
"rector/rector": "^0.15.2",
Expand All @@ -42,7 +42,7 @@
"saschaegerer/phpstan-typo3": "^1.8.0",
"symplify/easy-coding-standard": "^11.0",
"phpstan/phpstan-strict-rules": "^1.4.4",
"typo3/cms-rte-ckeditor": "^10.4 || ^11.5 || ^12.0"
"typo3/cms-rte-ckeditor": "^10.4 || ^11.5 || ^12.4"
},
"replace": {
"typo3-ter/typo3-encore": "self.version"
Expand Down
37 changes: 6 additions & 31 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,19 @@ parameters:
path: Classes/Asset/TagRenderer.php

-
message: "#^Strict comparison using \\!\\=\\= between '' and '1' will always evaluate to true\\.$#"
count: 1
path: Classes/Middleware/AssetsMiddleware.php

-
message: "#^Only booleans are allowed in a negated boolean, mixed given\\.$#"
count: 1
path: Classes/ViewHelpers/Stimulus/ActionViewHelper.php

-
message: "#^Only booleans are allowed in \\|\\|, mixed given on the left side\\.$#"
message: "#^Call to function is_array\\(\\) with array will always evaluate to true\\.$#"
count: 1
path: Classes/ViewHelpers/Stimulus/ActionViewHelper.php
path: Classes/Form/FormDataProvider/RichtextEncoreConfiguration.php

-
message: "#^Only booleans are allowed in \\|\\|, mixed given on the right side\\.$#"
message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#"
count: 1
path: Classes/ViewHelpers/Stimulus/ActionViewHelper.php
path: Classes/Form/FormDataProvider/RichtextEncoreConfiguration.php

-
message: "#^Only booleans are allowed in a negated boolean, mixed given\\.$#"
count: 1
path: Classes/ViewHelpers/Stimulus/ControllerViewHelper.php

-
message: "#^Only booleans are allowed in an if condition, mixed given\\.$#"
count: 1
path: Classes/ViewHelpers/Stimulus/ControllerViewHelper.php

-
message: "#^Only booleans are allowed in a negated boolean, mixed given\\.$#"
count: 1
path: Classes/ViewHelpers/Stimulus/TargetViewHelper.php

-
message: "#^Only booleans are allowed in an if condition, mixed given\\.$#"
message: "#^Strict comparison using \\!\\=\\= between '' and '1' will always evaluate to true\\.$#"
count: 1
path: Classes/ViewHelpers/Stimulus/TargetViewHelper.php
path: Classes/Middleware/AssetsMiddleware.php

-
message: "#^Only booleans are allowed in an if condition, mixed given\\.$#"
Expand Down

0 comments on commit 8dba6b9

Please sign in to comment.