Skip to content

Commit

Permalink
[TASK] Reflect codeEditor langauge based on selection
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminkott committed Oct 16, 2024
1 parent 5924324 commit 879107d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Classes/Form/DataProvider/CodeEditorFormatDataProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package bk2k/syntax.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace BK2K\Syntax\Form\DataProvider;

use TYPO3\CMS\Backend\Form\FormDataProviderInterface;

class CodeEditorFormatDataProvider implements FormDataProviderInterface
{
public function addData(array $result): array
{
if ($result['tableName'] !== 'tt_content' || $result['recordTypeValue'] !== 'syntax') {
return $result;
}

// @todo refactor when core provides api to retrieve registered packages or gracefully fallbacks
$syntaxLanguage = $result['databaseRow']['syntax_language'][0] ?? '';
if (in_array($syntaxLanguage, ['css', 'html', 'javascript', 'json', 'php', 'sql', 'typoscript', 'xml'])) {
$result['processedTca']['columns']['bodytext']['config']['format'] = $syntaxLanguage;
}

return $result;
}
}
10 changes: 10 additions & 0 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
* LICENSE file that was distributed with this source code.
*/

use BK2K\Syntax\Form\DataProvider\CodeEditorFormatDataProvider;
use TYPO3\CMS\Backend\Form\FormDataProvider\EvaluateDisplayConditions;
use TYPO3\CMS\Backend\Form\FormDataProvider\TcaColumnsOverrides;
use TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider;
use TYPO3\CMS\Core\Imaging\IconRegistry;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
Expand All @@ -26,3 +29,10 @@
SvgIconProvider::class,
['source' => 'EXT:syntax/Resources/Public/Icons/ContentElements/content-element-syntax.svg']
);

$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['tcaDatabaseRecord'][CodeEditorFormatDataProvider::class] = [
'depends' => [
TcaColumnsOverrides::class,
EvaluateDisplayConditions::class,
],
];

0 comments on commit 879107d

Please sign in to comment.