Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
54ca87b
FEAT Adapt for TYPO3 13
cbaur Oct 22, 2024
475fec5
Drops support for TYPO3 11 LTS
maechler Oct 24, 2024
a8e6287
Migrates tests to phpunit v10
maechler Oct 24, 2024
9f51801
Fixes functional tests by setting up a minimal fake request
maechler Oct 24, 2024
0b5b2d0
Merge branch 'main' into typo3-v13
butu Feb 21, 2025
d7b8744
Merge pull request #256 from butu/typo3-v13
maechler Feb 25, 2025
2135264
Add slug to pages fixture
maechler Mar 25, 2025
ed62bba
Fix TypoScript setup not loaded for functional tests
maechler Mar 25, 2025
9607e15
Fix deprecation warnings for StandaloneView
maechler Mar 25, 2025
298ea0a
Update TCPDF and FPDI versions used for tests
maechler Mar 25, 2025
3172fb4
Update expected example output PDFs
maechler Mar 25, 2025
32ca9ee
Migrate tests to `#[Test]` attribute
maechler Mar 25, 2025
329ba02
Remove old hook `['tslib/class.tslib_fe.php']['isOutputting']` disabl…
maechler Apr 17, 2025
d3a5d9e
Add page cache disabling with AfterCacheableContentIsGeneratedEvent
maechler Apr 28, 2025
a982f2e
Migrate StopOutputMiddleware from TSFE to OutputService
maechler Apr 28, 2025
ce6f5a9
Update build image from `ubuntu-20.04` to `ubuntu-24.04`
maechler Apr 30, 2025
10fd22f
Remove `readonly` from `AfterCacheableContentIsGeneratedEventListener…
maechler Apr 30, 2025
07aa3a6
Update TER upload image from `ubuntu-20.04` to `ubuntu-24.04`
maechler Apr 30, 2025
eac84d4
Fix typo in the support question issue template
maechler May 2, 2025
9c085e2
Update changelog
maechler May 3, 2025
b72b0f4
Update docs regarding TypoScript page type retrieval
maechler May 3, 2025
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
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/support-question.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ assignees: maechler
- Have you googled your question?
- Have you asked your colleagues for help?

If you could answer all this questions with yes, please feel free to open an issue with your question. We will try our best to help you.
If you could answer all these questions with yes, please feel free to open an issue with your question. We will try our best to help you.
11 changes: 5 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ on:

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04

strategy:
fail-fast: false
matrix:
env:
- { TYPO3_VERSION: 11, PHP_VERSION: 7.4 }
- { TYPO3_VERSION: 11, PHP_VERSION: 8.0 }
- { TYPO3_VERSION: 12, PHP_VERSION: 8.1 }
- { TYPO3_VERSION: 12, PHP_VERSION: 8.2 }
- { TYPO3_VERSION: 12, PHP_VERSION: 8.3 }
- { TYPO3_VERSION: 13, PHP_VERSION: 8.3 }
- { TYPO3_VERSION: 13, PHP_VERSION: 8.4 }

env:
TCPDF_VERSION: 6.6.2
FPDI_VERSION: 2.5.0
TCPDF_VERSION: 6.8.2
FPDI_VERSION: 2.6.3

steps:
- name: Checkout
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/ter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ on:
- "**"
jobs:
TERUpload:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog for TYPO3 CMS Extension pdfviewhelpers

## 3.1.0 - Not yet released

- Adds support for TYPO3 13 LTS
- Drops support for TYPO3 11 LTS
- Drops support for PHP < 8.1

## 3.0.2 - February 8, 2025

- Fixes version in docs and `ext_emconf.php`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Bithost\Pdfviewhelpers\Hooks;
namespace Bithost\Pdfviewhelpers\EventListener;

/* * *
*
Expand Down Expand Up @@ -30,26 +30,25 @@
* This copyright notice MUST APPEAR in all copies of the script!
* * */

use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use Bithost\Pdfviewhelpers\Service\OutputService;
use TYPO3\CMS\Frontend\Event\AfterCacheableContentIsGeneratedEvent;

/**
* TypoScriptFrontendController
* AfterCacheableContentIsGeneratedEventListener
*
* @author Markus Mächler <markus.maechler@bithost.ch>, Esteban Gehring <esteban.gehring@bithost.ch>
*/
class TypoScriptFrontendControllerHook implements SingletonInterface
class AfterCacheableContentIsGeneratedEventListener
{
/**
* Prevent any output when a pdf is rendered, especially any headers being set!
*/
public function isOutputting(array &$params, TypoScriptFrontendController $ref): void
public function __construct(
protected OutputService $outputService,
) {
}

public function __invoke(AfterCacheableContentIsGeneratedEvent $event): void
{
if (
isset($params['pObj']->applicationData['tx_pdfviewhelpers']['pdfOutput'])
&& $params['pObj']->applicationData['tx_pdfviewhelpers']['pdfOutput'] === true
) {
$params['enableOutput'] = false;
if ($this->outputService->shouldDisablePageCache()) {
$event->disableCaching();
}
}
}
40 changes: 34 additions & 6 deletions Classes/Middleware/Frontend/StopOutputMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,52 @@

namespace Bithost\Pdfviewhelpers\Middleware\Frontend;

/* * *
*
* This file is part of the "PDF ViewHelpers" Extension for TYPO3 CMS.
*
* (c) 2016 Markus Mächler <markus.maechler@bithost.ch>, Bithost GmbH
* Esteban Gehring <esteban.gehring@bithost.ch>, Bithost GmbH
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
* * */

use Bithost\Pdfviewhelpers\Service\OutputService;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use TYPO3\CMS\Core\Http\NullResponse;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class StopOutputMiddleware implements MiddlewareInterface
{
public function __construct(
protected OutputService $outputService,
) {
}

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$response = $handler->handle($request);

if (
GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() >= 11
&& ($GLOBALS['TSFE']->applicationData['tx_pdfviewhelpers']['pdfOutput'] ?? false)
) {
if ($this->outputService->isOutputDestinationOut()) {
// Avoid sending additional request header or body data if TCPDF has already sent a response
return new NullResponse();
}

Expand Down
70 changes: 70 additions & 0 deletions Classes/Service/OutputService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

declare(strict_types=1);

namespace Bithost\Pdfviewhelpers\Service;

/* * *
*
* This file is part of the "PDF ViewHelpers" Extension for TYPO3 CMS.
*
* (c) 2016 Markus Mächler <markus.maechler@bithost.ch>, Bithost GmbH
* Esteban Gehring <esteban.gehring@bithost.ch>, Bithost GmbH
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
* * */

use TYPO3\CMS\Core\SingletonInterface;

/**
* OutputService
*
* @author Markus Mächler <markus.maechler@bithost.ch>, Esteban Gehring <esteban.gehring@bithost.ch>
*/
class OutputService implements SingletonInterface
{
protected bool $isOutputDestinationOut = false;

protected bool $disableCache = true;

public function shouldDisablePageCache(): bool
{
return $this->isOutputDestinationOut() && $this->getDisableCache();
}

public function isOutputDestinationOut(): bool
{
return $this->isOutputDestinationOut;
}

public function setIsOutputDestinationOut(bool $isOutputDestinationOut): void
{
$this->isOutputDestinationOut = $isOutputDestinationOut;
}

public function getDisableCache(): bool
{
return $this->disableCache;
}

public function setDisableCache(bool $disableCache): void
{
$this->disableCache = $disableCache;
}
}
19 changes: 11 additions & 8 deletions Classes/ViewHelpers/DocumentViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@
use Bithost\Pdfviewhelpers\Exception\Exception;
use Bithost\Pdfviewhelpers\Exception\ValidationException;
use Bithost\Pdfviewhelpers\Model\BasePDF;
use Bithost\Pdfviewhelpers\Service\OutputService;
use setasign\Fpdi\PdfParser\PdfParserException;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

/**
* DocumentViewHelper
Expand All @@ -60,6 +59,13 @@ class DocumentViewHelper extends AbstractPDFViewHelper
*/
protected array $tcpdfReturnContentDestinations = ['S', 'E'];

protected OutputService $outputService;

public function injectOutputService(OutputService $outputService): void
{
$this->outputService = $outputService;
}

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -95,8 +101,8 @@ public function initialize()

$this->arguments['outputDestination'] = $this->conversionService->convertSpeakingOutputDestinationToTcpdfOutputDestination($this->arguments['outputDestination']);

if (isset($GLOBALS['TSFE']->applicationData) && in_array($this->arguments['outputDestination'], $this->tcpdfOutputContentDestinations)) {
$GLOBALS['TSFE']->applicationData['tx_pdfviewhelpers']['pdfOutput'] = true;
if (in_array($this->arguments['outputDestination'], $this->tcpdfOutputContentDestinations)) {
$this->outputService->setIsOutputDestinationOut(true);
}

if (!empty($this->settings['config']['class'])) {
Expand Down Expand Up @@ -129,10 +135,7 @@ public function initialize()
$this->getPDF()->setCreator($this->arguments['creator']);
$this->getPDF()->disableTcpdfLink(); // Part for increasing accessibility (ua-1)

//Disables cache if set so and in frontend mode
if (isset($GLOBALS['TSFE']) && $GLOBALS['TSFE'] instanceof TypoScriptFrontendController && $this->settings['config']['disableCache']) {
$GLOBALS['TSFE']->set_no_cache('EXT:pdfviewhelpers force disabled caching, see plugin.tx_pdfviewhelpers.settings.config.disableCache', true);
}
$this->outputService->setDisableCache($this->settings['config']['disableCache'] === '1');

$this->viewHelperVariableContainer->add('DocumentViewHelper', 'hyphenFile', $this->arguments['hyphenFile']);
$this->viewHelperVariableContainer->addOrUpdate('DocumentViewHelper', 'defaultHeaderFooterScope', BasePDF::SCOPE_DOCUMENT);
Expand Down
5 changes: 5 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ services:

Bithost\Pdfviewhelpers\:
resource: '../Classes/*'

Bithost\Pdfviewhelpers\EventListener\AfterCacheableContentIsGeneratedEventListener:
tags:
- name: event.listener
identifier: 'bithost/pdfviewhelpers/disable-page-cache'
2 changes: 1 addition & 1 deletion Configuration/TypoScript/Extensions/News/setup.typoscript
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[getTSFE() && getTSFE().type == 28032013]
[request && traverse(request.getQueryParams(), 'type') == 28032013]
pageNewsPDF = PAGE
pageNewsPDF {
typeNum = 28032013
Expand Down
4 changes: 2 additions & 2 deletions Documentation/ConfigurationReference/ExtNews/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Please make sure that all your configuration is limited to the page type ``28032

::

[getTSFE() && getTSFE().type == 28032013]
[request && traverse(request.getQueryParams(), 'type') == 28032013]
plugin.tx_pdfviewhelpers.settings {
text {
types {
Expand Down Expand Up @@ -61,7 +61,7 @@ that is located in ``EXT:yourext/Resources/Private/Templates/Extensions/News/Tem

::

[getTSFE() && getTSFE().type == 28032013]
[request && traverse(request.getQueryParams(), 'type') == 28032013]
plugin.tx_news {
view {
templateRootPaths {
Expand Down
45 changes: 38 additions & 7 deletions Tests/Functional/AbstractFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,19 @@
* This copyright notice MUST APPEAR in all copies of the script!
* * */

use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\View\ViewFactoryData;
use TYPO3\CMS\Core\View\ViewFactoryInterface;
use TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager;
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
use Smalot\PdfParser\Document;
use Smalot\PdfParser\Parser;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
use TYPO3\CMS\Core\TypoScript\AST\Node\RootNode;
use TYPO3\CMS\Core\TypoScript\FrontendTypoScript;

/**
* BaseFunctionalTest
Expand Down Expand Up @@ -69,20 +77,43 @@ public function setUp(): void
$this->importCSVDataSet($this->getFixtureAbsolutePath('pages.csv'));
$this->setUpFrontendRootPage(
1,
array_merge($baseTypoScripts, $this->typoScriptFiles),
[ 'setup' => array_merge($baseTypoScripts, $this->typoScriptFiles)],
);

/** @var BackendConfigurationManager $backendConfManager */
$backendConfigurationManager = $this->get(BackendConfigurationManager::class);
$backendTypoScriptSetup = $backendConfigurationManager->getTypoScriptSetup(new InternalRequest());

$frontendTypoScript = new FrontendTypoScript(new RootNode(), [], [], []);
$frontendTypoScript->setSetupArray($backendTypoScriptSetup);

$GLOBALS['TYPO3_REQUEST'] = (new InternalRequest())
->withPageId(1)
->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE)
->withAttribute('frontend.typoscript', $frontendTypoScript);
}

protected function renderFluidTemplate(string $templatePath, array $variables = []): string
{
/** @var StandaloneView $standaloneView */
$standaloneView = GeneralUtility::makeInstance(StandaloneView::class);
if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() < 13) {
/** @var StandaloneView $view */
$view = GeneralUtility::makeInstance(StandaloneView::class);

$view->setFormat('html');
$view->setTemplatePathAndFilename($templatePath);
} else {
/** @var ViewFactoryInterface $viewFactory */
$viewFactory = GeneralUtility::makeInstance(ViewFactoryInterface::class);
$viewFactoryData = new ViewFactoryData(
templateRootPaths: [$this->getFixtureExtPath('')],
templatePathAndFilename: $templatePath,
);
$view = $viewFactory->create($viewFactoryData);
}

$standaloneView->setFormat('html');
$standaloneView->setTemplatePathAndFilename($templatePath);
$standaloneView->assignMultiple($variables);
$view->assignMultiple($variables);

return (string) $standaloneView->render();
return $view->render();
}

protected function getFixtureExtPath(string $path): string
Expand Down
Loading