Fix broken data processing within model in newer TYPO3 version

TYPO3 changed how models are instantiated and prepared.
We now adopt the code to still initialize the data processing.
Furthermore, the feature is now covered with a test.

Relates: #11596
This commit is contained in:
Daniel Siepmann (Codappix) 2025-02-05 12:24:43 +01:00
parent 4e1d158923
commit 3fae8867a4
7 changed files with 117 additions and 25 deletions
Classes/Domain/Model
Documentation/Changelog
Tests/Functional
Domain/Model
Frontend
DatesTest.php
DatesTestFixtures
Fixtures/Extensions/example/Resources/Private/Templates/Date
ext_emconf.php

View file

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace WerkraumMedia\Events\Domain\Model;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Annotation\ORM\Cascade;
use TYPO3\CMS\Extbase\Annotation\ORM\Lazy;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
@ -60,6 +61,8 @@ class Event extends AbstractEntity
protected string $pages = '';
protected array $resolvedPages = [];
/**
* @var ObjectStorage<Category>
*/
@ -91,16 +94,18 @@ class Event extends AbstractEntity
public function __construct()
{
$this->initStorageObjects();
}
public function injectDataProcessingForModels(DataProcessingForModels $dataProcessing): void
{
$this->dataProcessing = $dataProcessing;
$this->initializeDataProcessing();
}
public function initializeObject(): void
{
$this->initStorageObjects();
$this->initializeDataProcessing();
}
private function initializeDataProcessing(): void
{
$this->dataProcessing = GeneralUtility::makeInstance(DataProcessingForModels::class);
}
protected function initStorageObjects(): void
@ -341,14 +346,13 @@ class Event extends AbstractEntity
public function getPages(): array
{
static $pages = null;
if (is_array($pages)) {
return $pages;
if ($this->resolvedPages !== []) {
return $this->resolvedPages;
}
$pages = $this->dataProcessing->process($this);
$this->resolvedPages = $this->dataProcessing->process($this);
return $pages;
return $this->resolvedPages;
}
public function addCategory(Category $category): void

View file

@ -0,0 +1,38 @@
5.0.1
=====
Breaking
--------
Nothing
Features
--------
Nothing
Fixes
-----
* Fix broken data processing within model in newer TYPO3 version.
TYPO3 changed how models are instantiated and prepared.
We now adopt the code to still initialize the data processing.
Furthermore, the feature is now covered with a test.
* Fix broken data processing caching within model.
Each model might have different pages.
The previous caching implementation would share the result between multiple
instances.
This is now solved via an internal property instead of static variable.
Tasks
-----
Nothing
Deprecation
-----------
Nothing

View file

@ -2,27 +2,16 @@
declare(strict_types=1);
namespace WerkraumMedia\Events\Tests\Unit\Domain\Model;
namespace WerkraumMedia\Events\Tests\Functional\Domain\Model;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
use WerkraumMedia\Events\Domain\Model\Category;
use WerkraumMedia\Events\Domain\Model\Event;
use WerkraumMedia\Events\Tests\Functional\AbstractFunctionalTestCase;
class EventTest extends TestCase
class EventTest extends AbstractFunctionalTestCase
{
#[Test]
public function canBeCreated(): void
{
$subject = new Event();
self::assertInstanceOf(
Event::class,
$subject
);
}
#[Test]
public function returnsSortedFeatures(): void
{

View file

@ -244,6 +244,19 @@ final class DatesTest extends AbstractFrontendTestCase
self::assertStringContainsString('<title>Title of Event 15.02.2023 00:00</title>', $html);
}
#[Test]
public function appliedDataProcessingForPagesAssociatedToEvent(): void
{
$this->importPHPDataSet(__DIR__ . '/DatesTestFixtures/DateWithAssociatedPageViaEvent.php');
$response = $this->issueDetailRequest();
self::assertSame(200, $response->getStatusCode());
$html = (string)$response->getBody();
self::assertStringContainsString('<li><a href="/referenced">Page 3 Referenced from event</a></li>', $html);
}
private function issueDetailRequest(): ResponseInterface
{
$request = new InternalRequest('https://example.com/');

View file

@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
return [
'tt_content' => [
0 => [
'uid' => '1',
'pid' => '1',
'CType' => 'events_dateshowtest',
'header' => 'Singleview',
],
],
'tx_events_domain_model_event' => [
0 => [
'uid' => '1',
'pid' => '2',
'title' => 'Title of Event with associated page',
'hidden' => '0',
'pages' => '3',
],
],
'tx_events_domain_model_date' => [
0 => [
'uid' => '1',
'pid' => '2',
'event' => '1',
'start' => '1676419200',
'end' => '1676484000',
],
],
'pages' => [
[
'uid' => 3,
'pid' => 1,
'title' => 'Page 3 Referenced from event',
'slug' => '/referenced',
],
],
];

View file

@ -70,4 +70,12 @@
</div>
</div>
<f:if condition="{date.event.pages.menu}">
<ul>
<f:for each="{date.event.pages.menu}" as="page">
<li><a href="{page.link}">{page.title}</a></li>
</f:for>
</ul>
</f:if>
</html>

View file

@ -9,7 +9,7 @@ $EM_CONF['events'] = [
'author' => 'Dirk Koritnik, Daniel Siepmann',
'author_email' => 'koritnik@werkraum-media.de, coding@daniel-siepmann.de',
'state' => 'stable',
'version' => '5.0.0',
'version' => '5.0.1',
'constraints' => [
'depends' => [
'typo3' => '',