create event for render_location hook

This commit is contained in:
Art4 2025-02-14 10:19:55 +00:00
parent 85fceaa16e
commit b3ef18bed7
5 changed files with 18 additions and 6 deletions

View file

@ -14,7 +14,6 @@ use Friendica\App\Page;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Core\ACL; use Friendica\Core\ACL;
use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Hook;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
@ -1472,7 +1471,11 @@ class Conversation
} }
$locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => '']; $locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => ''];
Hook::callAll('render_location', $locate);
$locate = $this->eventDispatcher->dispatch(
new ArrayFilterEvent(ArrayFilterEvent::RENDER_LOCATION, $locate),
)->getArray();
$location_html = $locate['html'] ?: Strings::escapeHtml($locate['location'] ?: $locate['coord'] ?: ''); $location_html = $locate['html'] ?: Strings::escapeHtml($locate['location'] ?: $locate['coord'] ?: '');
$this->item->localize($item); $this->item->localize($item);

View file

@ -50,6 +50,7 @@ final class HookEventBridge
ArrayFilterEvent::NETWORK_TO_NAME => 'network_to_name', ArrayFilterEvent::NETWORK_TO_NAME => 'network_to_name',
ArrayFilterEvent::CONVERSATION_START => 'conversation_start', ArrayFilterEvent::CONVERSATION_START => 'conversation_start',
ArrayFilterEvent::DISPLAY_ITEM => 'display_item', ArrayFilterEvent::DISPLAY_ITEM => 'display_item',
ArrayFilterEvent::RENDER_LOCATION => 'render_location',
HtmlFilterEvent::HEAD => 'head', HtmlFilterEvent::HEAD => 'head',
HtmlFilterEvent::FOOTER => 'footer', HtmlFilterEvent::FOOTER => 'footer',
HtmlFilterEvent::PAGE_HEADER => 'page_header', HtmlFilterEvent::PAGE_HEADER => 'page_header',
@ -79,6 +80,7 @@ final class HookEventBridge
ArrayFilterEvent::NETWORK_TO_NAME => 'onArrayFilterEvent', ArrayFilterEvent::NETWORK_TO_NAME => 'onArrayFilterEvent',
ArrayFilterEvent::CONVERSATION_START => 'onArrayFilterEvent', ArrayFilterEvent::CONVERSATION_START => 'onArrayFilterEvent',
ArrayFilterEvent::DISPLAY_ITEM => 'onArrayFilterEvent', ArrayFilterEvent::DISPLAY_ITEM => 'onArrayFilterEvent',
ArrayFilterEvent::RENDER_LOCATION => 'onArrayFilterEvent',
HtmlFilterEvent::HEAD => 'onHtmlFilterEvent', HtmlFilterEvent::HEAD => 'onHtmlFilterEvent',
HtmlFilterEvent::FOOTER => 'onHtmlFilterEvent', HtmlFilterEvent::FOOTER => 'onHtmlFilterEvent',
HtmlFilterEvent::PAGE_HEADER => 'onHtmlFilterEvent', HtmlFilterEvent::PAGE_HEADER => 'onHtmlFilterEvent',

View file

@ -38,6 +38,8 @@ final class ArrayFilterEvent extends Event
public const DISPLAY_ITEM = 'friendica.data.display_item'; public const DISPLAY_ITEM = 'friendica.data.display_item';
public const RENDER_LOCATION = 'friendica.data.render_location';
private array $array; private array $array;
public function __construct(string $name, array $array) public function __construct(string $name, array $array)

View file

@ -10,7 +10,6 @@ namespace Friendica\Object;
use Friendica\Content\ContactSelector; use Friendica\Content\ContactSelector;
use Friendica\Content\Feature; use Friendica\Content\Feature;
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Core\Hook;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\DI; use Friendica\DI;
@ -315,8 +314,14 @@ class Post
$sparkle = ' sparkle'; $sparkle = ' sparkle';
} }
$eventDispatcher = DI::eventDispatcher();
$locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => '']; $locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => ''];
Hook::callAll('render_location', $locate);
$locate = $eventDispatcher->dispatch(
new ArrayFilterEvent(ArrayFilterEvent::RENDER_LOCATION, $locate),
)->getArray();
$location_html = $locate['html'] ?: Strings::escapeHtml($locate['location'] ?: $locate['coord'] ?: ''); $location_html = $locate['html'] ?: Strings::escapeHtml($locate['location'] ?: $locate['coord'] ?: '');
// process action responses - e.g. like/dislike/attend/agree/whatever // process action responses - e.g. like/dislike/attend/agree/whatever
@ -631,8 +636,6 @@ class Post
], ],
]; ];
$eventDispatcher = DI::eventDispatcher();
$arr = ['item' => $item, 'output' => $tmp_item]; $arr = ['item' => $item, 'output' => $tmp_item];
$arr = $eventDispatcher->dispatch( $arr = $eventDispatcher->dispatch(

View file

@ -39,6 +39,7 @@ class HookEventBridgeTest extends TestCase
ArrayFilterEvent::NETWORK_TO_NAME => 'onArrayFilterEvent', ArrayFilterEvent::NETWORK_TO_NAME => 'onArrayFilterEvent',
ArrayFilterEvent::CONVERSATION_START => 'onArrayFilterEvent', ArrayFilterEvent::CONVERSATION_START => 'onArrayFilterEvent',
ArrayFilterEvent::DISPLAY_ITEM => 'onArrayFilterEvent', ArrayFilterEvent::DISPLAY_ITEM => 'onArrayFilterEvent',
ArrayFilterEvent::RENDER_LOCATION => 'onArrayFilterEvent',
HtmlFilterEvent::HEAD => 'onHtmlFilterEvent', HtmlFilterEvent::HEAD => 'onHtmlFilterEvent',
HtmlFilterEvent::FOOTER => 'onHtmlFilterEvent', HtmlFilterEvent::FOOTER => 'onHtmlFilterEvent',
HtmlFilterEvent::PAGE_HEADER => 'onHtmlFilterEvent', HtmlFilterEvent::PAGE_HEADER => 'onHtmlFilterEvent',
@ -169,6 +170,7 @@ class HookEventBridgeTest extends TestCase
[ArrayFilterEvent::NETWORK_TO_NAME, 'network_to_name'], [ArrayFilterEvent::NETWORK_TO_NAME, 'network_to_name'],
[ArrayFilterEvent::CONVERSATION_START, 'conversation_start'], [ArrayFilterEvent::CONVERSATION_START, 'conversation_start'],
[ArrayFilterEvent::DISPLAY_ITEM, 'display_item'], [ArrayFilterEvent::DISPLAY_ITEM, 'display_item'],
[ArrayFilterEvent::RENDER_LOCATION, 'render_location'],
]; ];
} }