]> git.mxchange.org Git - friendica.git/commitdiff
Create Event for display_item hook
authorArt4 <art4@wlabs.de>
Fri, 14 Feb 2025 09:42:57 +0000 (09:42 +0000)
committerArt4 <art4@wlabs.de>
Fri, 14 Feb 2025 09:42:57 +0000 (09:42 +0000)
src/Content/Conversation.php
src/Core/Hooks/HookEventBridge.php
src/Event/ArrayFilterEvent.php
src/Object/Post.php
tests/Unit/Core/Hooks/HookEventBridgeTest.php

index 16ca762698bb1dfa0a006272b8526f78d1958689..4175398a64a2534bf310108ebf5e4c780fb0e32c 100644 (file)
@@ -1572,7 +1572,10 @@ class Conversation
                        ];
 
                        $arr = ['item' => $item, 'output' => $tmp_item];
-                       Hook::callAll('display_item', $arr);
+
+                       $arr = $this->eventDispatcher->dispatch(
+                               new ArrayFilterEvent(ArrayFilterEvent::DISPLAY_ITEM, $arr),
+                       )->getArray();
 
                        $threads[] = [
                                'id'      => $item['id'],
index ffe16210c75281e02a42ee54ea93fa5ecf34a394..50f8945b4741f27577aeaa83279a8007c8df3cb2 100644 (file)
@@ -49,6 +49,7 @@ final class HookEventBridge
                ArrayFilterEvent::PHOTO_UPLOAD_FORM  => 'photo_upload_form',
                ArrayFilterEvent::NETWORK_TO_NAME    => 'network_to_name',
                ArrayFilterEvent::CONVERSATION_START => 'conversation_start',
+               ArrayFilterEvent::DISPLAY_ITEM       => 'display_item',
                HtmlFilterEvent::HEAD                => 'head',
                HtmlFilterEvent::FOOTER              => 'footer',
                HtmlFilterEvent::PAGE_HEADER         => 'page_header',
@@ -77,6 +78,7 @@ final class HookEventBridge
                        ArrayFilterEvent::PHOTO_UPLOAD_FORM  => 'onArrayFilterEvent',
                        ArrayFilterEvent::NETWORK_TO_NAME    => 'onArrayFilterEvent',
                        ArrayFilterEvent::CONVERSATION_START => 'onArrayFilterEvent',
+                       ArrayFilterEvent::DISPLAY_ITEM       => 'onArrayFilterEvent',
                        HtmlFilterEvent::HEAD                => 'onHtmlFilterEvent',
                        HtmlFilterEvent::FOOTER              => 'onHtmlFilterEvent',
                        HtmlFilterEvent::PAGE_HEADER         => 'onHtmlFilterEvent',
index 6c90a9d01d83ce8d1e01712592c20094d02a30ce..75f1eb86207f6aa33c223e462dad0d80f74f1884 100644 (file)
@@ -36,6 +36,8 @@ final class ArrayFilterEvent extends Event
 
        public const CONVERSATION_START = 'friendica.data.conversation_start';
 
+       public const DISPLAY_ITEM = 'friendica.data.display_item';
+
        private array $array;
 
        public function __construct(string $name, array $array)
index b5ad33f56e80f01d760fd5884e7ae2f55a65fcaf..769d74576c70e400ac67bfa88c90b9e2c3e9d4a1 100644 (file)
@@ -14,6 +14,7 @@ use Friendica\Core\Hook;
 use Friendica\Core\Protocol;
 use Friendica\Core\Renderer;
 use Friendica\DI;
+use Friendica\Event\ArrayFilterEvent;
 use Friendica\Model\Contact;
 use Friendica\Model\Conversation;
 use Friendica\Model\Item;
@@ -630,8 +631,13 @@ class Post
                        ],
                ];
 
+               $eventDispatcher = DI::eventDispatcher();
+
                $arr = ['item' => $item, 'output' => $tmp_item];
-               Hook::callAll('display_item', $arr);
+
+               $arr = $eventDispatcher->dispatch(
+                       new ArrayFilterEvent(ArrayFilterEvent::DISPLAY_ITEM, $arr),
+               )->getArray();
 
                $result = $arr['output'];
 
index 0e9e47659056cc2d63d1055315ac8c3536a98eff..eed89c343acd561916bdbc3a485494ff2686e351 100644 (file)
@@ -38,6 +38,7 @@ class HookEventBridgeTest extends TestCase
                        ArrayFilterEvent::PHOTO_UPLOAD_FORM  => 'onArrayFilterEvent',
                        ArrayFilterEvent::NETWORK_TO_NAME    => 'onArrayFilterEvent',
                        ArrayFilterEvent::CONVERSATION_START => 'onArrayFilterEvent',
+                       ArrayFilterEvent::DISPLAY_ITEM       => 'onArrayFilterEvent',
                        HtmlFilterEvent::HEAD                => 'onHtmlFilterEvent',
                        HtmlFilterEvent::FOOTER              => 'onHtmlFilterEvent',
                        HtmlFilterEvent::PAGE_HEADER         => 'onHtmlFilterEvent',
@@ -167,6 +168,7 @@ class HookEventBridgeTest extends TestCase
                        [ArrayFilterEvent::PHOTO_UPLOAD_FORM, 'photo_upload_form'],
                        [ArrayFilterEvent::NETWORK_TO_NAME, 'network_to_name'],
                        [ArrayFilterEvent::CONVERSATION_START, 'conversation_start'],
+                       [ArrayFilterEvent::DISPLAY_ITEM, 'display_item'],
                ];
        }