[PLUGINS][Repeat] Repeat template override WIP.

This commit is contained in:
Eliseu Amaro 2021-10-29 00:33:24 +01:00
parent 0f358a9c5d
commit 9a23e03330
Signed by: eliseuamaro
GPG Key ID: 96DA09D4B97BC2D5
5 changed files with 50 additions and 3 deletions

View File

@ -31,6 +31,7 @@ use App\Core\Modules\NoteHandlerPlugin;
use App\Entity\Note; use App\Entity\Note;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\RedirectException; use App\Util\Exception\RedirectException;
use App\Util\Formatting;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
class Repeat extends NoteHandlerPlugin class Repeat extends NoteHandlerPlugin
@ -77,6 +78,17 @@ class Repeat extends NoteHandlerPlugin
return Event::next; return Event::next;
} }
public function onOverrideTemplateImport(string $current_template, string $default, string &$response)
{
switch ($current_template) {
case '/network/feed.html.twig':
$response = "plugins/repeat/cards/note/view.html.twig";
return Event::stop;
}
return Event::next;
}
public function onAddRoute(RouteLoader $r): bool public function onAddRoute(RouteLoader $r): bool
{ {
// Add/remove note to/from repeats // Add/remove note to/from repeats

View File

@ -0,0 +1,22 @@
{% extends '/cards/note/view.html.twig' %}
{% macro macro_note(note, replies) %}
{% set nickname = note.getActorNickname() %}
{% set fullname = note.getActorFullname() %}
{% set actor_url = note.getActor().getUrl() %}
{% set repeat_of = note.getRepeatOf() %}
<article class="h-entry hentry note">
{{ block('note_sidebar') }}
<div class="note-wrapper">
<div tabindex="0" title="{{ 'Begin a note by the user: ' | trans }} {{ nickname }}." class="note-info">
{{ block('note_author') }}
{{ block('note_actions') }}
</div>
<section tabindex="0" role="dialog" class="e-content entry-content note-content">
{{ _self.macro_note_minimal(note) }}
</section>
{{ block('note_replies') }}
</div>
</article>
{% endmacro macro_note %}

View File

@ -69,6 +69,7 @@ class Extension extends AbstractExtension
new TwigFunction('config', [Runtime::class, 'getConfig']), new TwigFunction('config', [Runtime::class, 'getConfig']),
new TwigFunction('icon', [Runtime::class, 'embedSvgIcon'], ['needs_environment' => true]), new TwigFunction('icon', [Runtime::class, 'embedSvgIcon'], ['needs_environment' => true]),
new TwigFunction('is_firefox', [Runtime::class, 'isFirefox']), new TwigFunction('is_firefox', [Runtime::class, 'isFirefox']),
new TwigFunction('handle_override_template_import', [Runtime::class, 'handleOverrideTemplateImport']),
]; ];
} }
} }

View File

@ -125,6 +125,15 @@ class Runtime implements RuntimeExtensionInterface, EventSubscriberInterface
return $var instanceof $instance; return $var instanceof $instance;
} }
public function handleOverrideTemplateImport(string $template, string $default_import): string
{
$result = '';
if (Event::handle('OverrideTemplateImport', [$template, $default_import, &$result]) !== Event::stop) {
$result = $default_import;
}
return $result;
}
// ---------------------------------------------------------- // ----------------------------------------------------------
/** /**

View File

@ -1,5 +1,6 @@
{% extends 'stdgrid.html.twig' %} {% extends 'stdgrid.html.twig' %}
{% import "/cards/note/view.html.twig" as noteView %} {% set override_import = handle_override_template_import('/network/feed.html.twig', '/cards/note/view.html.twig') %}
{% import override_import as noteView %}
{% block title %}{% if page_title is defined %}{{ page_title | trans }}{% endif %}{% endblock %} {% block title %}{% if page_title is defined %}{{ page_title | trans }}{% endif %}{% endblock %}
@ -14,8 +15,10 @@
<div class="h-feed hfeed notes"> <div class="h-feed hfeed notes">
{% if notes is defined and notes is not empty %} {% if notes is defined and notes is not empty %}
{% for conversation in notes %} {% for conversation in notes %}
{% block current_note %}
{{ noteView.macro_note(conversation['note'], conversation['replies']) }} {{ noteView.macro_note(conversation['note'], conversation['replies']) }}
<hr tabindex="0" title="{{ 'End of note and replies.' | trans }}"> <hr tabindex="0" title="{{ 'End of note and replies.' | trans }}">
{% endblock current_note %}
{% endfor %} {% endfor %}
{% else %} {% else %}
<div id="empty-notes"><h1>{% trans %}No notes here.{% endtrans %}</h1></div> <div id="empty-notes"><h1>{% trans %}No notes here.{% endtrans %}</h1></div>