You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be great to add a ModifyJsonContentObjectDataEvent in order to modify data in \FriendsOfTYPO3\Headless\ContentObject\JsonContentObject. Here is a patch that would add this Event to the current 4.x dev branch.
Subject: [PATCH] Headless v4 + TYPO3 v12: add ModifyJsonContentObjectDataEvent
---
Index: Classes/ContentObject/JsonContentObject.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/Classes/ContentObject/JsonContentObject.php b/Classes/ContentObject/JsonContentObject.php
--- a/Classes/ContentObject/JsonContentObject.php (revision d5821b400dceaee34264b17c7f3489a5b1841b7d)
+++ b/Classes/ContentObject/JsonContentObject.php (date 1689667532763)
@@ -25,6 +25,7 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\AbstractContentObject;
use TYPO3\CMS\Frontend\ContentObject\ContentDataProcessor;
+use Psr\EventDispatcher\EventDispatcherInterface;
use function is_array;
use function strpos;
@@ -47,6 +48,13 @@
$this->headlessUserInt = GeneralUtility::makeInstance(HeadlessUserInt::class);
}
+ private EventDispatcherInterface $eventDispatcher;
+
+ public function injectEventDispatcher(EventDispatcherInterface $eventDispatcher): void
+ {
+ $this->eventDispatcher = $eventDispatcher;
+ }
+
/**
* Rendering the cObject, JSON
* @param array $conf Array of TypoScript properties
@@ -69,6 +77,13 @@
$data = $this->processFieldWithDataProcessing($conf);
}
+ $event = $this->eventDispatcher->dispatch(
+ new \FriendsOfTYPO3\Headless\Event\ModifyJsonContentObjectDataEvent($conf, $data)
+ );
+ if (!empty($event->getData())) {
+ $data = $event->getData();
+ }
+
$json = '';
if (is_array($data)) {
Index: Classes/Event/ModifyJsonContentObjectDataEvent.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/Classes/Event/ModifyJsonContentObjectDataEvent.php b/Classes/Event/ModifyJsonContentObjectDataEvent.php
new file mode 100644
--- /dev/null (date 1689667797403)
+++ b/Classes/Event/ModifyJsonContentObjectDataEvent.php (date 1689667797403)
@@ -0,0 +1,41 @@
+<?php
+
+declare(strict_types=1);
+
+namespace FriendsOfTYPO3\Headless\Event;
+
+/**
+ * \FriendsOfTYPO3\Headless\Event\ModifyJsonContentObjectDataEvent
+ */
+final class ModifyJsonContentObjectDataEvent
+{
+ public function __construct(
+ private array $conf,
+ private array $data,
+ ) {
+ }
+
+ /**
+ * @return array
+ */
+ public function getConf(): array
+ {
+ return $this->conf;
+ }
+
+ /**
+ * @return array
+ */
+ public function getData(): array
+ {
+ return $this->data;
+ }
+
+ /**
+ * @param array $data
+ */
+ public function setData(array $data): void
+ {
+ $this->data = $data;
+ }
+}
The text was updated successfully, but these errors were encountered:
It would be great to add a ModifyJsonContentObjectDataEvent in order to modify data in \FriendsOfTYPO3\Headless\ContentObject\JsonContentObject. Here is a patch that would add this Event to the current 4.x dev branch.
The text was updated successfully, but these errors were encountered: