forked from GNUsocial/gnu-social
[TWIG] Remove kludge event TwigPopulateVars
This commit is contained in:
parent
fda998e335
commit
67d62cf37b
@ -19,30 +19,8 @@
|
||||
|
||||
namespace Component\Left;
|
||||
|
||||
use App\Core\Event;
|
||||
use App\Core\Log;
|
||||
use App\Core\Modules\Component;
|
||||
use App\Util\Common;
|
||||
use Exception;
|
||||
|
||||
class Left extends Component
|
||||
{
|
||||
public function onEndTwigPopulateVars(array &$vars)
|
||||
{
|
||||
try {
|
||||
$user = Common::user();
|
||||
if ($user != null) {
|
||||
$actor = $user->getActor();
|
||||
$vars['user_id'] = $user->getId();
|
||||
$vars['user_nickname'] = $user->getNickname();
|
||||
$vars['user_tags'] = $actor->getSelfTags();
|
||||
$vars['user_followers'] = $actor->getFollowersCount();
|
||||
$vars['user_followed'] = $actor->getFollowedCount();
|
||||
$vars['user_avatar'] = $actor->getAvatarUrl();
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
Log::error('Got an exception while populating variables for the left panel: ' . $e);
|
||||
}
|
||||
return Event::next;
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ class Posting extends Component
|
||||
* @throws RedirectException
|
||||
* @throws ServerException
|
||||
*/
|
||||
public function onStartTwigPopulateVars(array &$vars): bool
|
||||
public function onAppendRightPostingBlock(array $vars, array &$res): bool
|
||||
{
|
||||
if (($user = Common::user()) === null) {
|
||||
return Event::next;
|
||||
@ -106,7 +106,7 @@ class Posting extends Component
|
||||
}
|
||||
}
|
||||
|
||||
$vars['post_form'] = $form->createView();
|
||||
$res = $form->createView();
|
||||
|
||||
return Event::next;
|
||||
}
|
||||
|
@ -19,14 +19,8 @@
|
||||
|
||||
namespace Component\Right;
|
||||
|
||||
use App\Core\Event;
|
||||
use App\Core\Modules\Component;
|
||||
use App\Util\Common;
|
||||
|
||||
class Right extends Component
|
||||
{
|
||||
public function onStartTwigPopulateVars(array &$vars)
|
||||
{
|
||||
return Event::next;
|
||||
}
|
||||
}
|
||||
|
@ -71,19 +71,19 @@ class Cover extends Plugin
|
||||
* @param array $vars
|
||||
*
|
||||
* @return bool hook value; true means continue processing, false means stop.
|
||||
*/
|
||||
public function onStartTwigPopulateVars(array &$vars): bool
|
||||
{
|
||||
/*if (Common::user() != null) {
|
||||
$cover = DB::find('cover', ['actor_id' => Common::user()->getId()]);
|
||||
if ($cover != null) {
|
||||
$vars['profile_extras'][] = ['name' => 'cover', 'vars' => ['img' => '/cover']];
|
||||
} else {
|
||||
$vars['profile_extras'][] = ['name' => 'cover', 'vars' => []];
|
||||
}
|
||||
}*/
|
||||
return Event::next;
|
||||
}
|
||||
*
|
||||
* public function onStartTwigPopulateVars(array &$vars): bool
|
||||
* {
|
||||
* if (Common::user() != null) {
|
||||
* $cover = DB::find('cover', ['actor_id' => Common::user()->getId()]);
|
||||
* if ($cover != null) {
|
||||
* $vars['profile_extras'][] = ['name' => 'cover', 'vars' => ['img' => '/cover']];
|
||||
* } else {
|
||||
* $vars['profile_extras'][] = ['name' => 'cover', 'vars' => []];
|
||||
* }
|
||||
* }
|
||||
* return Event::next;
|
||||
* }*/
|
||||
|
||||
/**
|
||||
* Output our dedicated stylesheet
|
||||
|
@ -24,6 +24,7 @@ namespace Plugin\Directory;
|
||||
use App\Core\Event;
|
||||
use App\Core\Modules\Plugin;
|
||||
use App\Core\Router\RouteLoader;
|
||||
use App\Core\Router\Router;
|
||||
|
||||
class Directory extends Plugin
|
||||
{
|
||||
@ -39,17 +40,16 @@ class Directory extends Plugin
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate twig vars
|
||||
* Add Links to menu
|
||||
*
|
||||
* @param array $vars
|
||||
* @param array $res out menu items
|
||||
*
|
||||
* @return bool hook value; true means continue processing, false means stop.
|
||||
*/
|
||||
public function onStartTwigPopulateVars(array &$vars): bool
|
||||
public function onAddMainNavigationItem(array $vars, array &$res): bool
|
||||
{
|
||||
$vars['main_nav_tabs'][] = ['title' => 'Actors', 'route' => 'directory_actors'];
|
||||
$vars['main_nav_tabs'][] = ['title' => 'Groups', 'route' => 'directory_groups'];
|
||||
|
||||
$res[] = ['title' => 'Actors', 'path' => Router::url('directory_actors', [])];
|
||||
$res[] = ['title' => 'Groups', 'path' => Router::url('directory_groups', [])];
|
||||
return Event::next;
|
||||
}
|
||||
}
|
||||
|
@ -27,12 +27,12 @@ use App\Core\Form;
|
||||
use function App\Core\I18n\_m;
|
||||
use App\Core\Modules\NoteHandlerPlugin;
|
||||
use App\Core\Router\RouteLoader;
|
||||
use App\Core\Router\Router;
|
||||
use App\Entity\Note;
|
||||
use App\Util\Common;
|
||||
use App\Util\Exception\InvalidFormException;
|
||||
use App\Util\Exception\NoSuchNoteException;
|
||||
use App\Util\Exception\RedirectException;
|
||||
use App\Util\Formatting;
|
||||
use App\Util\Nickname;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
@ -114,12 +114,10 @@ class Favourite extends NoteHandlerPlugin
|
||||
return Event::next;
|
||||
}
|
||||
|
||||
public function onInsertLeftPanelLink(string $user_nickname, &$res): bool
|
||||
public function onAddProfileNavigationItem(array $vars, array &$res): bool
|
||||
{
|
||||
$res[] = Formatting::twigRenderString(<<<END
|
||||
<a href="{{ path("actor_favourites_nickname", {'nickname' : user_nickname}) }}" class='hover-effect {{ active("favourites") }}'>Favourites</a>
|
||||
<a href="{{ path("actor_reverse_favourites_nickname", {'nickname' : user_nickname}) }}" class='hover-effect {{ active("reverse_favourites") }}'>Reverse Favs</a>
|
||||
END, ['user_nickname' => $user_nickname]);
|
||||
$res[] = ['title' => 'Favourites', 'path' => Router::url('actor_favourites_nickname', ['nickname' => $vars['nickname']])];
|
||||
$res[] = ['title' => 'Reverse Favourites', 'path' => Router::url('actor_reverse_favourites_nickname', ['nickname' => $vars['nickname']])];
|
||||
return Event::next;
|
||||
}
|
||||
|
||||
|
@ -70,14 +70,14 @@ class Poll extends NoteHandlerPlugin
|
||||
* @param array $vars
|
||||
*
|
||||
* @return bool hook value; true means continue processing, false means stop.
|
||||
*/
|
||||
public function onStartTwigPopulateVars(array &$vars): bool
|
||||
{
|
||||
$vars['tabs'][] = ['title' => 'Poll',
|
||||
'href' => 'newpoll',
|
||||
];
|
||||
return Event::next;
|
||||
}
|
||||
*
|
||||
* public function onStartTwigPopulateVars(array &$vars): bool
|
||||
* {
|
||||
* $vars['tabs'][] = ['title' => 'Poll',
|
||||
* 'href' => 'newpoll',
|
||||
* ];
|
||||
* return Event::next;
|
||||
* }*/
|
||||
|
||||
/**
|
||||
* Output our dedicated stylesheet
|
||||
|
@ -71,22 +71,22 @@ class ProfileColor extends Plugin
|
||||
* @param array $vars
|
||||
*
|
||||
* @return bool hook value; true means continue processing, false means stop.
|
||||
*/
|
||||
public function onStartTwigPopulateVars(array &$vars): bool
|
||||
{
|
||||
/*$vars['profile_tabs'][] = [
|
||||
'title' => 'Color',
|
||||
'desc' => 'Change your profile color.',
|
||||
'path' => 'profilecolor/profilecolor.html.twig',
|
||||
];*/
|
||||
if (Common::user() != null) {
|
||||
$color = DB::find('profile_color', ['actor_id' => Common::user()->getId()]);
|
||||
if ($color != null) {
|
||||
$vars['profile_extras'][] = ['name' => 'profilecolor', 'vars' => ['color' => $color->getColor()]];
|
||||
}
|
||||
}
|
||||
return Event::next;
|
||||
}
|
||||
*
|
||||
* public function onStartTwigPopulateVars(array &$vars): bool
|
||||
* {
|
||||
* /*$vars['profile_tabs'][] = [
|
||||
* 'title' => 'Color',
|
||||
* 'desc' => 'Change your profile color.',
|
||||
* 'path' => 'profilecolor/profilecolor.html.twig',
|
||||
* ];
|
||||
* if (Common::user() != null) {
|
||||
* $color = DB::find('profile_color', ['actor_id' => Common::user()->getId()]);
|
||||
* if ($color != null) {
|
||||
* $vars['profile_extras'][] = ['name' => 'profilecolor', 'vars' => ['color' => $color->getColor()]];
|
||||
* }
|
||||
* }
|
||||
* return Event::next;
|
||||
* }*/
|
||||
|
||||
/**
|
||||
* Output our dedicated stylesheet
|
||||
|
@ -89,8 +89,12 @@ class Controller extends AbstractController implements EventSubscriberInterface
|
||||
$request = $event->getRequest();
|
||||
|
||||
$this->request = $request;
|
||||
$this->vars = ['controller' => $controller, 'request' => $request, 'have_user' => Common::user() !== null];
|
||||
Event::handle('StartTwigPopulateVars', [&$this->vars]);
|
||||
|
||||
$this->vars = ['controller' => $controller, 'request' => $request];
|
||||
$user = Common::user();
|
||||
if ($user !== null) {
|
||||
$this->vars['current_actor'] = $user->getActor();
|
||||
}
|
||||
|
||||
$event->stopPropagation();
|
||||
return $event;
|
||||
@ -111,10 +115,9 @@ class Controller extends AbstractController implements EventSubscriberInterface
|
||||
}
|
||||
|
||||
$this->vars = array_merge_recursive($this->vars, $response);
|
||||
Event::handle('EndTwigPopulateVars', [&$this->vars]);
|
||||
|
||||
$template = $this->vars['_template'];
|
||||
unset($this->vars['_template'], $this->vars['request'], $response['_template']);
|
||||
unset($this->vars['_template'], $response['_template']);
|
||||
|
||||
// Respond in the most preferred acceptable content type
|
||||
$accept = $request->getAcceptableContentTypes() ?: ['text/html'];
|
||||
|
@ -265,7 +265,7 @@ class Actor extends Entity
|
||||
Cache::delete('selftags-' . $this->id);
|
||||
}
|
||||
|
||||
public function getFollowersCount()
|
||||
public function getSubscribersCount()
|
||||
{
|
||||
return Cache::get('followers-' . $this->id,
|
||||
function () {
|
||||
@ -274,7 +274,7 @@ class Actor extends Entity
|
||||
});
|
||||
}
|
||||
|
||||
public function getFollowedCount()
|
||||
public function getSubscriptionsCount()
|
||||
{
|
||||
return Cache::get('followed-' . $this->id,
|
||||
function () {
|
||||
|
@ -113,7 +113,7 @@ abstract class Common
|
||||
|
||||
public static function actor(): ?Actor
|
||||
{
|
||||
return self::user()->getActor();
|
||||
return self::user()?->getActor();
|
||||
}
|
||||
|
||||
public static function userNickname(): ?string
|
||||
|
@ -8,7 +8,7 @@
|
||||
<div class="h-feed hfeed notes">
|
||||
{% if notes is defined and notes is not empty %}
|
||||
{% for conversation in notes %}
|
||||
{% include '/note/view.html.twig' with {'note': conversation['note'], 'have_user': have_user, 'replies': conversation['replies']} only %}
|
||||
{% include '/note/view.html.twig' with {'note': conversation['note'], 'replies': conversation['replies']} only %}
|
||||
<hr tabindex="0" title="{{ 'End of note and replies.' | trans }}">
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
|
@ -16,21 +16,19 @@
|
||||
|
||||
{% if app.user %}
|
||||
<div class="note-actions">
|
||||
{% if have_user %}
|
||||
{% for current_action in get_note_actions(note) %}
|
||||
{{ form_start(current_action) }}
|
||||
{% if current_action.submit_favourite is defined %}
|
||||
{{ form_widget(current_action.submit_favourite) }}
|
||||
{% endif %}
|
||||
{% if current_action.submit_repeat is defined %}
|
||||
{{ form_widget(current_action.submit_repeat) }}
|
||||
{% endif %}
|
||||
{% if current_action.reply is defined %}
|
||||
{{ form_widget(current_action.reply) }}
|
||||
{% endif %}
|
||||
{{ form_end(current_action) }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% for current_action in get_note_actions(note) %}
|
||||
{{ form_start(current_action) }}
|
||||
{% if current_action.submit_favourite is defined %}
|
||||
{{ form_widget(current_action.submit_favourite) }}
|
||||
{% endif %}
|
||||
{% if current_action.submit_repeat is defined %}
|
||||
{{ form_widget(current_action.submit_repeat) }}
|
||||
{% endif %}
|
||||
{% if current_action.reply is defined %}
|
||||
{{ form_widget(current_action.reply) }}
|
||||
{% endif %}
|
||||
{{ form_end(current_action) }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
@ -6,12 +6,13 @@
|
||||
<aside class="panel-content accessibility-target">
|
||||
{% if app.user %}
|
||||
<section class='section-widget section-widget-padded' title="{{ 'Your profile information.' | trans }}">
|
||||
<a id="user" href="{{ path('actor_view_nickname', {'nickname' : user_nickname}) }}">
|
||||
<img src='{{ user_avatar }}' class="icon icon-avatar" alt="{{ 'Your account\'s avatar.' | trans }}">
|
||||
<a id="user" href="{{ path('actor_view_nickname', {'nickname' : current_actor.getNickname()}) }}">
|
||||
<img src='{{ current_actor.getAvatarUrl() }}' class="icon icon-avatar" alt="{{ 'Your account\'s avatar.' | trans }}">
|
||||
<div class="user-info">
|
||||
<strong id="user-nickname" title="{{ 'Your account\' nickname.' | trans }}">{{ user_nickname }}</strong>
|
||||
<strong id="user-nickname" title="{{ 'Your account\' nickname.' | trans }}">{{ current_actor.getNickname() }}</strong>
|
||||
|
||||
<nav class="user-tags">
|
||||
{% set user_tags = current_actor.getSelfTags() %}
|
||||
{% if user_tags %}
|
||||
{% for tag in user_tags %}
|
||||
<a href='#'> #{{ tag }}</a>
|
||||
@ -22,28 +23,26 @@
|
||||
</nav>
|
||||
|
||||
<section id="user-stats">
|
||||
{% if user_followers %}<h2>{{ 'Followers' | trans }} {{ user_followers }}</h2> {% endif %}
|
||||
{% if user_followed %}<h2>{{ 'Followed' | trans }} {{ user_followed }}</h2> {% endif %}
|
||||
<h2>{{ 'Subscriptions' | trans }} {{ current_actor.getSubscriptionsCount() }}</h2>
|
||||
<h2>{{ 'Subscribers' | trans }} {{ current_actor.getSubscribersCount() }}</h2>
|
||||
</section>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
|
||||
{# {% for extra in profile_extras %}
|
||||
{% include '/'~ extra.name ~ '/view.html.twig' with {'vars': extra.vars} only %}
|
||||
{% endfor %} #}
|
||||
|
||||
<nav tabindex="0" class="profile-navigation" title="{{ 'Navigate through account related pages.' | trans }}">
|
||||
<a title='{{ 'Your messages.' | trans }}' href='{{ path('settings') }}' class='{{ active("replies") }}'>
|
||||
Messages
|
||||
</a>
|
||||
|
||||
<a title='{{ 'Replies to your notes.' | trans }}' href="{{ path('replies', {'nickname' : user_nickname}) }}" class='{{ active("replies") }}'>
|
||||
<a title='{{ 'Replies to your notes.' | trans }}' href="{{ path('replies', {'nickname' : current_actor.getNickname()}) }}" class='{{ active("replies") }}'>
|
||||
Replies
|
||||
</a>
|
||||
|
||||
{% for link in handle_event('InsertLeftPanelLink', user_nickname) %}
|
||||
{{ link | raw }}
|
||||
|
||||
{% for tab in handle_event('AddProfileNavigationItem', {'nickname': current_actor.getNickname()}) %}
|
||||
<a href="{{ tab['path'] }}">
|
||||
{{ tab['title'] }}
|
||||
</a>
|
||||
{% endfor %}
|
||||
|
||||
<a title='{{ 'Access your account settings.' | trans }}' href="{{ path('settings') }}" class='{{ active('settings') }}'>
|
||||
@ -85,8 +84,8 @@
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
{% if user_nickname is defined %}
|
||||
<a href="{{ path("home_all", {'nickname' : user_nickname}) }}" class='{{ active("home_all") }}'>
|
||||
{% if app.user %}
|
||||
<a href="{{ path("home_all", {'nickname' : current_actor.getNickname()}) }}" class='{{ active("home_all") }}'>
|
||||
Home
|
||||
</a>
|
||||
{% endif %}
|
||||
@ -97,11 +96,11 @@
|
||||
</a>
|
||||
</li>
|
||||
|
||||
{% if main_nav_tabs is defined %}
|
||||
{% for tab in main_nav_tabs %}
|
||||
{% if app.user %}
|
||||
{% for link in handle_event('AddMainNavigationItem', {'nickname': current_actor.getNickname()}) %}
|
||||
<li>
|
||||
<a href="{{ path(tab['route']) }}" class='{{ active(tab['route']) }}'>
|
||||
{{ tab['title'] }}
|
||||
<a href="{{ link['path'] }}">
|
||||
{{ link['title'] }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
@ -5,39 +5,34 @@
|
||||
<a id="anchor-right-panel" class="anchor-hidden" title="{{ 'Press tab to access selected region!' | trans }}"></a>
|
||||
<aside class="panel-content accessibility-target">
|
||||
|
||||
{% if post_form is defined and not post_form.isRendered() %}
|
||||
<section class="section-widget" title={{ 'Create a new note.' | trans }}>
|
||||
<details class="section-title-details" title={{ 'Expand if you want to access more options.' | trans }}>
|
||||
<summary class="section-title-summary">
|
||||
{{ "Create a note" | trans }}{{ icon('arrow-down', 'icon icon-details-open') | raw }}
|
||||
</summary>
|
||||
{% set post_form = handle_event('AppendRightPostingBlock', {'request': request}) %}
|
||||
<section class="section-widget" title={{ 'Create a new note.' | trans }}>
|
||||
<details class="section-title-details" title={{ 'Expand if you want to access more options.' | trans }}>
|
||||
<summary class="section-title-summary">
|
||||
{{ "Create a note" | trans }}{{ icon('arrow-down', 'icon icon-details-open') | raw }}
|
||||
</summary>
|
||||
</details>
|
||||
|
||||
{% for tab in tabs %}
|
||||
<a class="section-title-menu-element" href={{ path(tab['href']) }}>{{ tab['title'] }}</a>
|
||||
{% endfor %}
|
||||
</details>
|
||||
<div class="section-form">
|
||||
<fieldset>
|
||||
{{ form_start(post_form) }}
|
||||
|
||||
<div class="section-form">
|
||||
<fieldset>
|
||||
{{ form_start(post_form) }}
|
||||
{{ form_row(post_form.to, {'attr': {'class': 'section-form-scope'}}) }}
|
||||
|
||||
{{ form_row(post_form.to, {'attr': {'class': 'section-form-scope'}}) }}
|
||||
{{ form_row(post_form.visibility, {'attr': {'class': 'section-form-scope'}}) }}
|
||||
|
||||
{{ form_row(post_form.visibility, {'attr': {'class': 'section-form-scope'}}) }}
|
||||
{{ form_row(post_form.content, {'attr': {'class': 'section-form-textarea'}}) }}
|
||||
|
||||
{{ form_row(post_form.content, {'attr': {'class': 'section-form-textarea'}}) }}
|
||||
<label for="{{ post_form.attachments.vars.id }}" class="section-form-options">
|
||||
{{ form_widget(post_form.attachments) }}
|
||||
</label>
|
||||
|
||||
<label for="{{ post_form.attachments.vars.id }}" class="section-form-options">
|
||||
{{ form_widget(post_form.attachments) }}
|
||||
</label>
|
||||
{{ form_row(post_form.post_note, {'attr': {'class': 'section-form-send'}}) }}
|
||||
|
||||
{{ form_row(post_form.post_note, {'attr': {'class': 'section-form-send'}}) }}
|
||||
|
||||
{{ form_end(post_form) }}
|
||||
</fieldset>
|
||||
</div>
|
||||
</section>
|
||||
{% endif %}
|
||||
{{ form_end(post_form) }}
|
||||
</fieldset>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{% set current_path = app.request.get('_route') %}
|
||||
{% if right_panel_vars is defined %}
|
||||
|
Loading…
Reference in New Issue
Block a user