]> git.mxchange.org Git - friendica.git/commitdiff
Create Event for contact_block_end hook
authorArt4 <art4@wlabs.de>
Thu, 20 Feb 2025 08:24:52 +0000 (08:24 +0000)
committerArt4 <art4@wlabs.de>
Thu, 20 Feb 2025 08:24:52 +0000 (08:24 +0000)
doc/Addons.md
doc/de/Addons.md
src/Content/Widget/ContactBlock.php
src/Core/Hooks/HookEventBridge.php
src/Event/HtmlFilterEvent.php
tests/Unit/Core/Hooks/HookEventBridgeTest.php

index 70b51c3066542fddf2143a5a0163491e919ed1b2..7b7e97e701172f50c6a33217733eb372f4005cab 100644 (file)
@@ -661,7 +661,7 @@ Called when a custom storage is used (e.g. webdav_storage)
 
 Hook data:
 - **name** (input): the name of the used storage backend
-- **data['storage']** (output): the storage instance to use (**must** implement `\Friendica\Core\Storage\IWritableStorage`) 
+- **data['storage']** (output): the storage instance to use (**must** implement `\Friendica\Core\Storage\IWritableStorage`)
 
 ### storage_config
 
@@ -876,7 +876,7 @@ Here is a complete list of all hook callbacks with file locations (as of 24-Sep-
 
 ### src/Content/ContactBlock.php
 
-    Hook::callAll('contact_block_end', $arr);
+    Hook::callAll('contact_block_end', $text);
 
 ### src/Content/Text/BBCode.php
 
index 607f2d50dc534810cd5bd020f08352ffb396db45..bfc010752891c7f3ed2adfd7f80430ae1bf86a8e 100644 (file)
@@ -359,10 +359,10 @@ Eine komplette Liste aller Hook-Callbacks mit den zugehörigen Dateien (am 01-Ap
 
     Hook::callAll('register_account', $uid);
     Hook::callAll('remove_user', $user);
-    
+
 ### src/Content/ContactBlock.php
 
-    Hook::callAll('contact_block_end', $arr);
+    Hook::callAll('contact_block_end', $text);
 
 ### src/Content/Text/BBCode.php
 
index b1d80653d4e14be386b9b9871fbd68add16bc112..2a9d14db3eda891bd073d7fbd5bb8298190adbe7 100644 (file)
@@ -8,11 +8,11 @@
 namespace Friendica\Content\Widget;
 
 use Friendica\Content\Text\HTML;
-use Friendica\Core\Hook;
 use Friendica\Core\Protocol;
 use Friendica\Core\Renderer;
 use Friendica\Database\DBA;
 use Friendica\DI;
+use Friendica\Event\HtmlFilterEvent;
 use Friendica\Model\Contact;
 use Friendica\Model\User;
 
@@ -26,7 +26,6 @@ class ContactBlock
        /**
         * Get HTML for contact block
         *
-        * @hook contact_block_end (contacts=>array, output=>string)
         * @return string Formatted HTML code or empty string
         */
        public static function getHTML(array $profile, int $visitor_uid = null): string
@@ -113,9 +112,11 @@ class ContactBlock
                        '$micropro' => $micropro,
                ]);
 
-               $arr = ['contacts' => $contacts, 'output' => $o];
+               $eventDispatcher = DI::eventDispatcher();
 
-               Hook::callAll('contact_block_end', $arr);
+               $o = $eventDispatcher->dispatch(
+                       new HtmlFilterEvent(HtmlFilterEvent::CONTACT_BLOCK_END, $o),
+               )->getHtml();
 
                return $o;
        }
index bc0615f368343af7c91fbf422ae946e3f519e056..943ba7eaa63bdf9dac89d6218fe35e52b4d7f75b 100644 (file)
@@ -64,6 +64,7 @@ final class HookEventBridge
                HtmlFilterEvent::PAGE_CONTENT_TOP        => 'page_content_top',
                HtmlFilterEvent::PAGE_END                => 'page_end',
                HtmlFilterEvent::JOT_TOOL                => 'jot_tool',
+               HtmlFilterEvent::CONTACT_BLOCK_END       => 'contact_block_end',
        ];
 
        /**
@@ -101,6 +102,7 @@ final class HookEventBridge
                        HtmlFilterEvent::PAGE_CONTENT_TOP        => 'onHtmlFilterEvent',
                        HtmlFilterEvent::PAGE_END                => 'onHtmlFilterEvent',
                        HtmlFilterEvent::JOT_TOOL                => 'onHtmlFilterEvent',
+                       HtmlFilterEvent::CONTACT_BLOCK_END       => 'onHtmlFilterEvent',
                ];
        }
 
index 83a852e08b571e57b7c95795c857a6871e78850d..cb8a3992dfbda19f8ee29fc876601b68cb0ef477 100644 (file)
@@ -28,6 +28,8 @@ final class HtmlFilterEvent extends Event
 
        public const JOT_TOOL = 'friendica.html.jot_tool';
 
+       public const CONTACT_BLOCK_END = 'friendica.html.contact_block_end';
+
        private string $html;
 
        public function __construct(string $name, string $html)
index e7d7aba55e5957f652e5cef0edf81ba4ad8e5f7a..b8fb3c48149cf7fc3c54da84107db83c44c4fbf8 100644 (file)
@@ -53,6 +53,7 @@ class HookEventBridgeTest extends TestCase
                        HtmlFilterEvent::PAGE_CONTENT_TOP        => 'onHtmlFilterEvent',
                        HtmlFilterEvent::PAGE_END                => 'onHtmlFilterEvent',
                        HtmlFilterEvent::JOT_TOOL                => 'onHtmlFilterEvent',
+                       HtmlFilterEvent::CONTACT_BLOCK_END       => 'onHtmlFilterEvent',
                ];
 
                $this->assertSame(
@@ -302,6 +303,7 @@ class HookEventBridgeTest extends TestCase
                        [HtmlFilterEvent::PAGE_CONTENT_TOP, 'page_content_top'],
                        [HtmlFilterEvent::PAGE_END, 'page_end'],
                        [HtmlFilterEvent::JOT_TOOL, 'jot_tool'],
+                       [HtmlFilterEvent::CONTACT_BLOCK_END, 'contact_block_end'],
                ];
        }