[COMPONENTS][RightPanel] AppendRightPanelBlock event refactored,

replaced with src/Twig/Rintime::getRightPanelBlocks
[COMPONENTS] Re-ordered onAppendRightPanelBlock event calls arguments for improved consistency across events
This commit is contained in:
Eliseu Amaro 2022-01-17 01:36:12 +00:00 committed by Hugo Sales
parent da7ae5e1f5
commit 184d0246a5
No known key found for this signature in database
GPG Key ID: 7D0C7EAFC9D835A0
7 changed files with 24 additions and 6 deletions

View File

@ -94,7 +94,7 @@ trait MetaCollectionTrait
* It's compose of two forms: one to select collections to add * It's compose of two forms: one to select collections to add
* the current item to, and another to create a new collection. * the current item to, and another to create a new collection.
*/ */
public function onAppendRightPanelBlock($vars, Request $request, &$res): bool public function onAppendRightPanelBlock(Request $request, $vars, &$res): bool
{ {
$user = Common::actor(); $user = Common::actor();
if (\is_null($user)) { if (\is_null($user)) {

View File

@ -59,6 +59,15 @@ class Group extends FeedController
/** /**
* View a group feed and give the option of creating it if it doesn't exist * View a group feed and give the option of creating it if it doesn't exist
*
* @throws \App\Util\Exception\NicknameEmptyException
* @throws \App\Util\Exception\NicknameNotAllowedException
* @throws \App\Util\Exception\NicknameTakenException
* @throws \App\Util\Exception\NicknameTooLongException
* @throws \App\Util\Exception\ServerException
* @throws RedirectException
*
* @return array
*/ */
public function groupViewNickname(Request $request, string $nickname) public function groupViewNickname(Request $request, string $nickname)
{ {

View File

@ -7,6 +7,7 @@
<div class="header-panel section-panel-right"> <div class="header-panel section-panel-right">
<aside class="panel-content accessibility-target"> <aside class="panel-content accessibility-target">
{% set current_path = app.request.get('_route') %}
{% set blocks = handle_event('AppendRightPostingBlock', request) %} {% set blocks = handle_event('AppendRightPostingBlock', request) %}
{% if blocks['post_form'] is defined %} {% if blocks['post_form'] is defined %}
<section class="section-widget" title="{{ 'Create a new note.' | trans }}"> <section class="section-widget" title="{{ 'Create a new note.' | trans }}">
@ -51,11 +52,10 @@
</section> </section>
{% endif %} {% endif %}
{% set current_path = app.request.get('_route') %} {% set extra_blocks = get_right_panel_blocks({'path': current_path, 'request': app.request, 'vars': (right_panel_vars | default)}) %}
{% for block in handle_event('AppendRightPanelBlock', {'path': current_path, 'request': request, 'vars': right_panel_vars | default }, request) %} {% for block in extra_blocks %}
{{ block | raw }} {{ block | raw }}
{% endfor %} {% endfor %}
</aside> </aside>
</div> </div>
{% endblock rightpanel %} {% endblock rightpanel %}

View File

@ -28,10 +28,11 @@ use App\Core\Event;
use App\Core\Modules\Plugin; use App\Core\Modules\Plugin;
use App\Util\Common; use App\Util\Common;
use App\Util\Formatting; use App\Util\Formatting;
use Symfony\Component\HttpFoundation\Request;
class AttachmentShowRelated extends Plugin class AttachmentShowRelated extends Plugin
{ {
public function onAppendRightPanelBlock($vars, $request, &$res): bool public function onAppendRightPanelBlock(Request $request, $vars, &$res): bool
{ {
if ($vars['path'] === 'note_attachment_show') { if ($vars['path'] === 'note_attachment_show') {
$related_notes = DB::dql('select n from attachment_to_note an ' $related_notes = DB::dql('select n from attachment_to_note an '

View File

@ -51,7 +51,7 @@ use Symfony\Component\HttpFoundation\Request;
class WebMonetization extends Plugin class WebMonetization extends Plugin
{ {
public function onAppendRightPanelBlock($vars, Request $request, &$res): bool public function onAppendRightPanelBlock(Request $request, $vars, &$res): bool
{ {
$user = Common::actor(); $user = Common::actor();
if (\is_null($user)) { if (\is_null($user)) {

View File

@ -78,6 +78,7 @@ class Extension extends AbstractExtension
new TwigFunction('mention', [Runtime::class, 'mention']), new TwigFunction('mention', [Runtime::class, 'mention']),
new TwigFunction('open_details', [Runtime::class, 'openDetails']), new TwigFunction('open_details', [Runtime::class, 'openDetails']),
new TwigFunction('show_stylesheets', [Runtime::class, 'getShowStylesheets']), new TwigFunction('show_stylesheets', [Runtime::class, 'getShowStylesheets']),
new TwigFunction('get_right_panel_blocks', [Runtime::class, 'getRightPanelBlocks']),
]; ];
} }
} }

View File

@ -88,6 +88,13 @@ class Runtime implements RuntimeExtensionInterface, EventSubscriberInterface
return $extra_actions; return $extra_actions;
} }
public function getRightPanelBlocks($vars)
{
$blocks = [];
Event::handle('AppendRightPanelBlock', [$this->request, $vars, &$blocks]);
return $blocks;
}
/** /**
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */