Skip to content
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
27 changes: 27 additions & 0 deletions Classes/Backend/Preview/ContentPreviewRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace B13\Codeblock\Backend\Preview;

/*
* This file is part of TYPO3 CMS-extension codeblock by b13.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*/

use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem;

class ContentPreviewRenderer extends \TYPO3\CMS\Backend\Preview\StandardContentPreviewRenderer
{
public function renderPageModulePreviewContent(GridColumnItem $item): string
{
$record = $item->getRecord();
if (trim($record['bodytext'] ?? '') !== '') {
return $this->linkEditContent(nl2br(htmlentities($record['bodytext'])), $record) . '<br />';
}
return parent::renderPageModulePreviewContent($item);
}
}
12 changes: 5 additions & 7 deletions Classes/DataProcessing/HighlightProcessor.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace B13\Codeblock\DataProcessing;
Expand All @@ -22,14 +23,11 @@
*/
class HighlightProcessor implements DataProcessorInterface
{
/**
* @var ContentDataProcessor
*/
protected $contentDataProcessor;
protected ContentDataProcessor $contentDataProcessor;

public function __construct()
public function __construct(ContentDataProcessor $contentDataProcessor)
{
$this->contentDataProcessor = GeneralUtility::makeInstance(ContentDataProcessor::class);
$this->contentDataProcessor = $contentDataProcessor;
}

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

// Let highlight.php decide which code language to use from all registered if "detect automatically" is selected.
if (!$processedData['data']['code_language']) {
if (!($processedData['data']['code_language'] ?? true)) {
$languages = $highlight->listLanguages();
$highlight->setAutodetectLanguages($languages);
$highlighted = $highlight->highlightAuto($processedData['data'][$fieldName]);
Expand Down
1 change: 1 addition & 0 deletions Classes/DataProvider/CodeLanguages.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace B13\Codeblock\DataProvider;
Expand Down
10 changes: 7 additions & 3 deletions Classes/Hooks/CodeblockPreviewRenderer.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace B13\Codeblock\Hooks;

/*
Expand All @@ -11,6 +12,7 @@

use TYPO3\CMS\Backend\View\PageLayoutView;
use TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface;
use TYPO3\CMS\Core\Configuration\Features;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
Expand All @@ -37,10 +39,12 @@ public function preProcess(
if ($row['CType'] === 'codeblock') {
if ($row['bodytext']) {
$bodytext = GeneralUtility::fixed_lgd_cs($row['bodytext'], 1000);
$itemContent .= $parentObject->linkEditContent(nl2br(htmlentities($bodytext)), $row) . '<br />';
$row['bodytext'] = $bodytext;
if ((GeneralUtility::makeInstance(Features::class))->isFeatureEnabled('fluidBasedPageModule') === false) {
$itemContent .= $parentObject->linkEditContent(nl2br(htmlentities($bodytext)), $row) . '<br />';
$drawItem = false;
}
}

$drawItem = false;
}
}
}
28 changes: 28 additions & 0 deletions Classes/Listener/PageContentPreviewRendering.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace B13\Codeblock\Listener;

/*
* This file is part of TYPO3 CMS-extension codeblock by b13.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*/

use TYPO3\CMS\Backend\View\Event\PageContentPreviewRenderingEvent;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class PageContentPreviewRendering
{
public function __invoke(PageContentPreviewRenderingEvent $event): void
{
$record = $event->getRecord();
if (($record['CType'] ?? '') === 'codeblock' && trim($record['bodytext'] ?? '') !== '') {
$record['bodytext'] = GeneralUtility::fixed_lgd_cs($record['bodytext'], 1000);
$event->setRecord($record);
}
}
}
15 changes: 15 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false

B13\Codeblock\:
resource: '../Classes/*'

B13\Codeblock\DataProcessing\HighlightProcessor:
public: true
B13\Codeblock\Listener\PageContentPreviewRendering:
tags:
- name: event.listener
identifier: 'b13/codeblock/page-content-preview-rendering'
7 changes: 6 additions & 1 deletion Configuration/TCA/Overrides/tt_content.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

defined('TYPO3') or die();

call_user_func(static function () {
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem(
'tt_content',
Expand Down Expand Up @@ -37,7 +39,7 @@
'fixedFont' => true,
],
],
]
],
];

$additionalColumns = [
Expand All @@ -60,4 +62,7 @@
'codeblock',
'before:bodytext'
);

// for fluidBasedPageModule enabled (always for TYPO3 > 11)
$GLOBALS['TCA']['tt_content']['types']['codeblock']['previewRenderer'] = \B13\Codeblock\Backend\Preview\ContentPreviewRenderer::class;
});
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"homepage": "https://github.com/b13/codeblock",
"license": ["GPL-2.0-or-later"],
"require": {
"scrivo/highlight.php": "^9.15"
"scrivo/highlight.php": "^9.15",
"php": "^7.4 || ~8.0",
"typo3/cms-core": "^10.4 || ^11.5 || ^12.0"
},
"replace": {
"b13/codeblock": "self.version"
Expand Down
4 changes: 2 additions & 2 deletions ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
'author_company' => 'b13 GmbH',
'state' => 'stable',
'clearCacheOnLoad' => true,
'version' => '1.4.0',
'version' => '2.0.0',
'constraints' => [
'depends' => [
'typo3' => '9.5.0-11.99.99',
'typo3' => '10.4.0-12.99.99',
],
],
];
9 changes: 6 additions & 3 deletions ext_localconf.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php
defined('TYPO3_MODE') or die();

defined('TYPO3') or die();

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

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