mirror of
https://github.com/friendica/friendica
synced 2025-03-03 20:28:26 +00:00
Create event for network_to_name hook
This commit is contained in:
parent
caef97752a
commit
3295b9055f
4 changed files with 12 additions and 1 deletions
|
@ -11,6 +11,7 @@ use Friendica\Core\Hook;
|
|||
use Friendica\Core\Protocol;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Event\ArrayFilterEvent;
|
||||
use Friendica\Util\Strings;
|
||||
|
||||
/**
|
||||
|
@ -113,6 +114,8 @@ class ContactSelector
|
|||
*/
|
||||
public static function networkToName(string $network, string $protocol = '', int $gsid = null): string
|
||||
{
|
||||
$eventDispatcher = DI::eventDispatcher();
|
||||
|
||||
$nets = [
|
||||
Protocol::DFRN => DI::l10n()->t('DFRN'),
|
||||
Protocol::OSTATUS => DI::l10n()->t('OStatus'),
|
||||
|
@ -135,7 +138,9 @@ class ContactSelector
|
|||
Protocol::BLUESKY => DI::l10n()->t('Bluesky'),
|
||||
];
|
||||
|
||||
Hook::callAll('network_to_name', $nets);
|
||||
$nets = $eventDispatcher->dispatch(
|
||||
new ArrayFilterEvent(ArrayFilterEvent::NETWORK_TO_NAME, $nets),
|
||||
)->getArray();
|
||||
|
||||
$search = array_keys($nets);
|
||||
$replace = array_values($nets);
|
||||
|
|
|
@ -47,6 +47,7 @@ final class HookEventBridge
|
|||
ArrayFilterEvent::POST_LOCAL => 'post_local',
|
||||
ArrayFilterEvent::POST_LOCAL_END => 'post_local_end',
|
||||
ArrayFilterEvent::PHOTO_UPLOAD_FORM => 'photo_upload_form',
|
||||
ArrayFilterEvent::NETWORK_TO_NAME => 'network_to_name',
|
||||
HtmlFilterEvent::HEAD => 'head',
|
||||
HtmlFilterEvent::FOOTER => 'footer',
|
||||
HtmlFilterEvent::PAGE_HEADER => 'page_header',
|
||||
|
@ -72,6 +73,7 @@ final class HookEventBridge
|
|||
ArrayFilterEvent::POST_LOCAL => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::POST_LOCAL_END => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::PHOTO_UPLOAD_FORM => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::NETWORK_TO_NAME => 'onArrayFilterEvent',
|
||||
HtmlFilterEvent::HEAD => 'onHtmlFilterEvent',
|
||||
HtmlFilterEvent::FOOTER => 'onHtmlFilterEvent',
|
||||
HtmlFilterEvent::PAGE_HEADER => 'onHtmlFilterEvent',
|
||||
|
|
|
@ -32,6 +32,8 @@ final class ArrayFilterEvent extends Event
|
|||
|
||||
public const PHOTO_UPLOAD_FORM = 'friendica.data.photo_upload_form';
|
||||
|
||||
public const NETWORK_TO_NAME = 'friendica.data.network_to_name';
|
||||
|
||||
private array $array;
|
||||
|
||||
public function __construct(string $name, array $array)
|
||||
|
|
|
@ -36,6 +36,7 @@ class HookEventBridgeTest extends TestCase
|
|||
ArrayFilterEvent::POST_LOCAL => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::POST_LOCAL_END => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::PHOTO_UPLOAD_FORM => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::NETWORK_TO_NAME => 'onArrayFilterEvent',
|
||||
HtmlFilterEvent::HEAD => 'onHtmlFilterEvent',
|
||||
HtmlFilterEvent::FOOTER => 'onHtmlFilterEvent',
|
||||
HtmlFilterEvent::PAGE_HEADER => 'onHtmlFilterEvent',
|
||||
|
@ -162,6 +163,7 @@ class HookEventBridgeTest extends TestCase
|
|||
[ArrayFilterEvent::POST_LOCAL, 'post_local'],
|
||||
[ArrayFilterEvent::POST_LOCAL_END, 'post_local_end'],
|
||||
[ArrayFilterEvent::PHOTO_UPLOAD_FORM, 'photo_upload_form'],
|
||||
[ArrayFilterEvent::NETWORK_TO_NAME, 'network_to_name'],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue