Skip to content

Commit 8bd8058

Browse files
author
Achim Fritz
committed
[TASK] TYPO3 v12 Support
1 parent 0ee38f0 commit 8bd8058

File tree

10 files changed

+100
-17
lines changed

10 files changed

+100
-17
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace B13\Codeblock\Backend\Preview;
6+
7+
/*
8+
* This file is part of TYPO3 CMS-extension codeblock by b13.
9+
*
10+
* It is free software; you can redistribute it and/or modify it under
11+
* the terms of the GNU General Public License, either version 2
12+
* of the License, or any later version.
13+
*/
14+
15+
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem;
16+
17+
class ContentPreviewRenderer extends \TYPO3\CMS\Backend\Preview\StandardContentPreviewRenderer
18+
{
19+
public function renderPageModulePreviewContent(GridColumnItem $item): string
20+
{
21+
$record = $item->getRecord();
22+
if (trim($record['bodytext'] ?? '') !== '') {
23+
return $this->linkEditContent(nl2br(htmlentities($record['bodytext'])), $record) . '<br />';
24+
}
25+
return parent::renderPageModulePreviewContent($item);
26+
}
27+
}

Classes/DataProcessing/HighlightProcessor.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace B13\Codeblock\DataProcessing;
@@ -22,14 +23,11 @@
2223
*/
2324
class HighlightProcessor implements DataProcessorInterface
2425
{
25-
/**
26-
* @var ContentDataProcessor
27-
*/
28-
protected $contentDataProcessor;
26+
protected ContentDataProcessor $contentDataProcessor;
2927

30-
public function __construct()
28+
public function __construct(ContentDataProcessor $contentDataProcessor)
3129
{
32-
$this->contentDataProcessor = GeneralUtility::makeInstance(ContentDataProcessor::class);
30+
$this->contentDataProcessor = $contentDataProcessor;
3331
}
3432

3533
/**
@@ -49,7 +47,7 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu
4947
$highlight = GeneralUtility::makeInstance(Highlighter::class);
5048

5149
// Let highlight.php decide which code language to use from all registered if "detect automatically" is selected.
52-
if (!$processedData['data']['code_language']) {
50+
if (!($processedData['data']['code_language'] ?? true)) {
5351
$languages = $highlight->listLanguages();
5452
$highlight->setAutodetectLanguages($languages);
5553
$highlighted = $highlight->highlightAuto($processedData['data'][$fieldName]);

Classes/DataProvider/CodeLanguages.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace B13\Codeblock\DataProvider;

Classes/Hooks/CodeblockPreviewRenderer.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace B13\Codeblock\Hooks;
34

45
/*
@@ -11,6 +12,7 @@
1112

1213
use TYPO3\CMS\Backend\View\PageLayoutView;
1314
use TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface;
15+
use TYPO3\CMS\Core\Configuration\Features;
1416
use TYPO3\CMS\Core\Utility\GeneralUtility;
1517

1618
/**
@@ -37,10 +39,12 @@ public function preProcess(
3739
if ($row['CType'] === 'codeblock') {
3840
if ($row['bodytext']) {
3941
$bodytext = GeneralUtility::fixed_lgd_cs($row['bodytext'], 1000);
40-
$itemContent .= $parentObject->linkEditContent(nl2br(htmlentities($bodytext)), $row) . '<br />';
42+
$row['bodytext'] = $bodytext;
43+
if ((GeneralUtility::makeInstance(Features::class))->isFeatureEnabled('fluidBasedPageModule') === false) {
44+
$itemContent .= $parentObject->linkEditContent(nl2br(htmlentities($bodytext)), $row) . '<br />';
45+
$drawItem = false;
46+
}
4147
}
42-
43-
$drawItem = false;
4448
}
4549
}
4650
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace B13\Codeblock\Listener;
6+
7+
/*
8+
* This file is part of TYPO3 CMS-extension codeblock by b13.
9+
*
10+
* It is free software; you can redistribute it and/or modify it under
11+
* the terms of the GNU General Public License, either version 2
12+
* of the License, or any later version.
13+
*/
14+
15+
use TYPO3\CMS\Backend\View\Event\PageContentPreviewRenderingEvent;
16+
use TYPO3\CMS\Core\Utility\GeneralUtility;
17+
18+
class PageContentPreviewRendering
19+
{
20+
public function __invoke(PageContentPreviewRenderingEvent $event): void
21+
{
22+
$record = $event->getRecord();
23+
if (($record['CType'] ?? '') === 'codeblock' && trim($record['bodytext'] ?? '') !== '') {
24+
$record['bodytext'] = GeneralUtility::fixed_lgd_cs($record['bodytext'], 1000);
25+
$event->setRecord($record);
26+
}
27+
}
28+
}

Configuration/Services.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
services:
2+
_defaults:
3+
autowire: true
4+
autoconfigure: true
5+
public: false
6+
7+
B13\Codeblock\:
8+
resource: '../Classes/*'
9+
10+
B13\Codeblock\DataProcessing\HighlightProcessor:
11+
public: true
12+
B13\Codeblock\Listener\PageContentPreviewRendering:
13+
tags:
14+
- name: event.listener
15+
identifier: 'b13/codeblock/page-content-preview-rendering'

Configuration/TCA/Overrides/tt_content.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
defined('TYPO3') or die();
4+
35
call_user_func(static function () {
46
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem(
57
'tt_content',
@@ -37,7 +39,7 @@
3739
'fixedFont' => true,
3840
],
3941
],
40-
]
42+
],
4143
];
4244

4345
$additionalColumns = [
@@ -60,4 +62,7 @@
6062
'codeblock',
6163
'before:bodytext'
6264
);
65+
66+
// for fluidBasedPageModule enabled (always for TYPO3 > 11)
67+
$GLOBALS['TCA']['tt_content']['types']['codeblock']['previewRenderer'] = \B13\Codeblock\Backend\Preview\ContentPreviewRenderer::class;
6368
});

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"homepage": "https://github.com/b13/codeblock",
66
"license": ["GPL-2.0-or-later"],
77
"require": {
8-
"scrivo/highlight.php": "^9.15"
8+
"scrivo/highlight.php": "^9.15",
9+
"php": "^7.4 || ~8.0",
10+
"typo3/cms-core": "^10.4 || ^11.5 || ^12.0"
911
},
1012
"replace": {
1113
"b13/codeblock": "self.version"

ext_emconf.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
'author_company' => 'b13 GmbH',
1010
'state' => 'stable',
1111
'clearCacheOnLoad' => true,
12-
'version' => '1.4.0',
12+
'version' => '2.0.0',
1313
'constraints' => [
1414
'depends' => [
15-
'typo3' => '9.5.0-11.99.99',
15+
'typo3' => '10.4.0-12.99.99',
1616
],
1717
],
1818
];

ext_localconf.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<?php
2-
defined('TYPO3_MODE') or die();
2+
3+
defined('TYPO3') or die();
34

45
call_user_func(static function () {
5-
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem']['codeblock'] =
6-
\B13\Codeblock\Hooks\CodeblockPreviewRenderer::class;
6+
if ((\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Information\Typo3Version::class))->getMajorVersion() < 12) {
7+
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem']['codeblock'] =
8+
\B13\Codeblock\Hooks\CodeblockPreviewRenderer::class;
9+
}
710

811
$iconRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconRegistry::class);
912
$iconRegistry->registerIcon(

0 commit comments

Comments
 (0)