ArrayFilterEvent::RENDER_LOCATION => 'render_location',
ArrayFilterEvent::ITEM_PHOTO_MENU => 'item_photo_menu',
ArrayFilterEvent::CONTACT_PHOTO_MENU => 'contact_photo_menu',
+ ArrayFilterEvent::PROFILE_SIDEBAR_ENTRY => 'profile_sidebar_enter',
+ ArrayFilterEvent::PROFILE_SIDEBAR => 'profile_sidebar',
ArrayFilterEvent::OEMBED_FETCH_END => 'oembed_fetch_url',
ArrayFilterEvent::PAGE_INFO => 'page_info_data',
ArrayFilterEvent::SMILEY_LIST => 'smilie',
ArrayFilterEvent::RENDER_LOCATION => 'onArrayFilterEvent',
ArrayFilterEvent::ITEM_PHOTO_MENU => 'onArrayFilterEvent',
ArrayFilterEvent::CONTACT_PHOTO_MENU => 'onArrayFilterEvent',
+ ArrayFilterEvent::PROFILE_SIDEBAR_ENTRY => 'onProfileSidebarEntryEvent',
+ ArrayFilterEvent::PROFILE_SIDEBAR => 'onArrayFilterEvent',
ArrayFilterEvent::OEMBED_FETCH_END => 'onOembedFetchEndEvent',
ArrayFilterEvent::PAGE_INFO => 'onArrayFilterEvent',
ArrayFilterEvent::SMILEY_LIST => 'onArrayFilterEvent',
$event->setArray($data);
}
+ /**
+ * Map the PROFILE_SIDEBAR_ENTRY event to `profile_sidebar_enter` hook
+ */
+ public static function onProfileSidebarEntryEvent(ArrayFilterEvent $event): void
+ {
+ $data = $event->getArray();
+
+ $profile = (array) $data['profile'] ?? [];
+
+ $data['profile'] = static::callHook($event->getName(), $profile);
+
+ $event->setArray($data);
+ }
+
/**
* Map the OEMBED_FETCH_END event to `oembed_fetch_url` hook
*/
public const CONTACT_PHOTO_MENU = 'friendica.data.contact_photo_menu';
+ public const PROFILE_SIDEBAR_ENTRY = 'friendica.data.profile_sidebar_entry';
+
+ public const PROFILE_SIDEBAR = 'friendica.data.profile_sidebar';
+
public const OEMBED_FETCH_END = 'friendica.data.oembed_fetch_end';
public const PAGE_INFO = 'friendica.data.page_info';
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\DI;
+use Friendica\Event\ArrayFilterEvent;
use Friendica\Network\HTTPException;
use Friendica\Protocol\Activity;
use Friendica\Protocol\Diaspora;
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
* @note Returns empty string if passed $profile is wrong type or not populated
- *
- * @hooks 'profile_sidebar_enter'
- * array $profile - profile data
- * @hooks 'profile_sidebar'
- * array $arr
*/
public static function getVCardHtml(array $profile, bool $block, bool $show_contacts): string
{
$profile['network_link'] = '';
- Hook::callAll('profile_sidebar_enter', $profile);
+ $eventDispatcher = DI::eventDispatcher();
+
+ $hook_data = [
+ 'profile' => $profile,
+ ];
+
+ $hook_data = $eventDispatcher->dispatch(
+ new ArrayFilterEvent(ArrayFilterEvent::PROFILE_SIDEBAR_ENTRY, $hook_data),
+ )->getArray();
+
+ $profile = $hook_data['profile'] ?? $profile;
$profile_url = $profile['url'];
'$network_url' => $network_url,
]);
- $arr = ['profile' => &$profile, 'entry' => &$o];
+ $hook_data = [
+ 'profile' => &$profile,
+ 'entry' => &$o,
+ ];
+
+ $hook_data = $eventDispatcher->dispatch(
+ new ArrayFilterEvent(ArrayFilterEvent::PROFILE_SIDEBAR, $hook_data),
+ )->getArray();
- Hook::callAll('profile_sidebar', $arr);
+ $profile = $hook_data['profile'] ?? $profile;
+ $o = $hook_data['entry'] ?? $o;
return $o;
}
ArrayFilterEvent::RENDER_LOCATION => 'onArrayFilterEvent',
ArrayFilterEvent::ITEM_PHOTO_MENU => 'onArrayFilterEvent',
ArrayFilterEvent::CONTACT_PHOTO_MENU => 'onArrayFilterEvent',
+ ArrayFilterEvent::PROFILE_SIDEBAR_ENTRY => 'onProfileSidebarEntryEvent',
+ ArrayFilterEvent::PROFILE_SIDEBAR => 'onArrayFilterEvent',
ArrayFilterEvent::OEMBED_FETCH_END => 'onOembedFetchEndEvent',
ArrayFilterEvent::PAGE_INFO => 'onArrayFilterEvent',
ArrayFilterEvent::SMILEY_LIST => 'onArrayFilterEvent',
);
}
+ public function testOnProfileSidebarEntryEventCallsHookWithCorrectValue(): void
+ {
+ $event = new ArrayFilterEvent(ArrayFilterEvent::PROFILE_SIDEBAR_ENTRY, ['profile' => ['uid' => 0, 'name' => 'original']]);
+
+ $reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
+ $reflectionProperty->setAccessible(true);
+
+ $reflectionProperty->setValue(null, function (string $name, array $data): array {
+ $this->assertSame('profile_sidebar_enter', $name);
+ $this->assertSame(['uid' => 0, 'name' => 'original'], $data);
+
+ return ['uid' => 0, 'name' => 'changed'];
+ });
+
+ HookEventBridge::onProfileSidebarEntryEvent($event);
+
+ $this->assertSame(
+ ['profile' => ['uid' => 0, 'name' => 'changed']],
+ $event->getArray(),
+ );
+ }
+
public function testOnOembedFetchEndEventCallsHookWithCorrectValue(): void
{
$event = new ArrayFilterEvent(ArrayFilterEvent::OEMBED_FETCH_END, ['url' => 'original_url']);
[ArrayFilterEvent::RENDER_LOCATION, 'render_location'],
[ArrayFilterEvent::ITEM_PHOTO_MENU, 'item_photo_menu'],
[ArrayFilterEvent::CONTACT_PHOTO_MENU, 'contact_photo_menu'],
+ [ArrayFilterEvent::PROFILE_SIDEBAR_ENTRY, 'profile_sidebar_enter'],
+ [ArrayFilterEvent::PROFILE_SIDEBAR, 'profile_sidebar'],
[ArrayFilterEvent::PAGE_INFO, 'page_info_data'],
[ArrayFilterEvent::SMILEY_LIST, 'smilie'],
[ArrayFilterEvent::JOT_NETWORKS, 'jot_networks'],
[ArrayFilterEvent::RENDER_LOCATION, 'friendica.data.render_location'],
[ArrayFilterEvent::ITEM_PHOTO_MENU, 'friendica.data.item_photo_menu'],
[ArrayFilterEvent::CONTACT_PHOTO_MENU, 'friendica.data.contact_photo_menu'],
+ [ArrayFilterEvent::PROFILE_SIDEBAR_ENTRY, 'friendica.data.profile_sidebar_entry'],
+ [ArrayFilterEvent::PROFILE_SIDEBAR, 'friendica.data.profile_sidebar'],
[ArrayFilterEvent::OEMBED_FETCH_END, 'friendica.data.oembed_fetch_end'],
[ArrayFilterEvent::PAGE_INFO, 'friendica.data.page_info'],
[ArrayFilterEvent::SMILEY_LIST, 'friendica.data.smiley_list'],