Skip to content

Commit

Permalink
[BUGFIX] Avoid NotInstantiableTypeException for type Folder
Browse files Browse the repository at this point in the history
Objects of class TYPO3\CMS\Core\Resource\File can't be exported
due to attached storage, which itself has EventDispatcher attached
which eventually leads to illegal Closures for EventListeners.
Right now, this happens for relations of type "folder".

In order to fix this, the File object needs somehow to be defined
as lazy. Another way could be to define a specific Model which
behaves as a replacement for the File object.

Yet another fix could be to avoid having eventDispatcher as a property
in ResourceStorage. This is used in many places, though.

Fixes: #172
  • Loading branch information
nhovratov committed Mar 28, 2024
1 parent 860b323 commit 4ac051e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 10 additions & 2 deletions Classes/Backend/Preview/PageLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace TYPO3\CMS\ContentBlocks\Backend\Preview;

use Psr\Http\Message\ServerRequestInterface;
use Symfony\Component\VarExporter\Exception\NotInstantiableTypeException;
use Symfony\Component\VarExporter\VarExporter;
use TYPO3\CMS\Backend\Controller\Event\ModifyPageLayoutContentEvent;
use TYPO3\CMS\Backend\Module\ModuleData;
Expand Down Expand Up @@ -153,8 +154,15 @@ protected function getContentBlockData(
);
// Avoid flooding cache with redundant data.
if ($resolvedData->resolved !== $pageRow) {
$exported = 'return ' . VarExporter::export($resolvedData) . ';';
$this->cache->set($cacheIdentifier, $exported);
try {
$exported = 'return ' . VarExporter::export($resolvedData) . ';';
$this->cache->set($cacheIdentifier, $exported);
} catch (NotInstantiableTypeException) {
// @todo objects of class TYPO3\CMS\Core\Resource\File can't be exported
// @todo due to attached storage, which itself has EventDispatcher attached
// @todo which eventually leads to illegal Closures for EventListeners.
// @todo Right now, this happens for relations of type "folder".
}
}
}
$contentBlockData = $this->contentBlockDataDecorator->decorate(
Expand Down
12 changes: 10 additions & 2 deletions Classes/Backend/Preview/PreviewRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace TYPO3\CMS\ContentBlocks\Backend\Preview;

use Psr\Http\Message\ServerRequestInterface;
use Symfony\Component\VarExporter\Exception\NotInstantiableTypeException;
use Symfony\Component\VarExporter\VarExporter;
use TYPO3\CMS\Backend\Preview\StandardContentPreviewRenderer;
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem;
Expand Down Expand Up @@ -80,8 +81,15 @@ public function renderPageModulePreviewContent(GridColumnItem $item): string
);
// Avoid flooding cache with redundant data.
if ($resolvedData->resolved !== $record) {
$exported = 'return ' . VarExporter::export($resolvedData) . ';';
$this->cache->set($cacheIdentifier, $exported);
try {
$exported = 'return ' . VarExporter::export($resolvedData) . ';';
$this->cache->set($cacheIdentifier, $exported);
} catch (NotInstantiableTypeException) {
// @todo objects of class TYPO3\CMS\Core\Resource\File can't be exported
// @todo due to attached storage, which itself has EventDispatcher attached
// @todo which eventually leads to illegal Closures for EventListeners.
// @todo Right now, this happens for relations of type "folder".
}
}
}
$data = $this->contentBlockDataDecorator->decorate(
Expand Down

0 comments on commit 4ac051e

Please sign in to comment.