[SETTINGS][PLUGIN][CONTROLLER] Populate profile tabs event added. Settings base template populated with such event for plugins and components.

Signed-off-by: Eliseu Amaro <mail@eliseuama.ro>
This commit is contained in:
Eliseu Amaro 2021-07-29 20:20:32 +01:00
parent 780d341939
commit efeb4b4ffe
11 changed files with 91 additions and 77 deletions

View File

@ -25,10 +25,12 @@ use App\Core\Event;
use App\Core\GSFile;
use App\Core\Modules\Component;
use App\Util\Common;
use Component\Avatar\Controller as C;
use Component\Avatar\Exception\NoAvatarException;
use Exception;
use Symfony\Component\Asset\Package;
use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;
use Symfony\Component\HttpFoundation\Request;
class Avatar extends Component
{
@ -39,7 +41,18 @@ class Avatar extends Component
return Event::next;
}
public function onEndTwigPopulateVars(array &$vars)
public function onPopulateProfileSettingsTabs(Request $request, &$tabs)
{
// TODO avatar template shouldn't be on settings folder
$tabs[] = ['title' => 'Avatar',
'desc' => 'Change your avatar.',
'controller' => C\Avatar::settings_avatar($request),
];
return Event::next;
}
public function onStartTwigPopulateVars(array &$vars)
{
if (Common::user() != null) {
$vars['user_avatar'] = self::getAvatarUrl();

View File

@ -59,13 +59,13 @@ class Avatar extends Controller
/**
* Local user avatar panel
*/
public function settings_avatar(Request $request)
public static function settings_avatar(Request $request)
{
$form = Form::create([
['avatar', FileType::class, ['label' => _m('Avatar'), 'help' => _m('You can upload your personal avatar. The maximum file size is 2MB.'), 'multiple' => false, 'required' => false]],
['avatar', FileType::class, ['label' => _m('Avatar'), 'help' => _m('You can upload your personal avatar. The maximum file size is 2MB.'), 'multiple' => false, 'required' => false]],
['remove', CheckboxType::class, ['label' => _m('Remove avatar'), 'help' => _m('Remove your avatar and use the default one'), 'required' => false, 'value' => false]],
['hidden', HiddenType::class, []],
['save', SubmitType::class, ['label' => _m('Submit')]],
['hidden', HiddenType::class, []],
['save', SubmitType::class, ['label' => _m('Submit')]],
]);
$form->handleRequest($request);

View File

@ -61,14 +61,14 @@ class Cover
*
* @return array template
*/
public function coverSettings(Request $request)
public static function coverSettings(Request $request)
{
$user = Common::user();
$actor_id = $user->getId();
$form = Form::create([
['cover', FileType::class, ['label' => _m('Cover'), 'help' => _m('You can upload your personal cover. The maximum file size is 2MB.'),
'constraints' => [
['cover', FileType::class, ['label' => _m('Cover'), 'help' => _m('You can upload your personal cover. The maximum file size is 2MB.'),
'constraints' => [
new F([
'maxSize' => '2048k',
'mimeTypes' => [

View File

@ -25,6 +25,8 @@ use App\Core\Event;
use App\Core\Modules\Plugin;
use App\Core\Router\RouteLoader;
use App\Util\Common;
use Plugin\Cover\Controller as C;
use Symfony\Component\HttpFoundation\Request;
/**
* Cover plugin main class
@ -52,6 +54,17 @@ class Cover extends Plugin
return Event::next;
}
public function onPopulateProfileSettingsTabs(Request $request, &$tabs)
{
$tabs[] = [
'title' => 'Cover',
'desc' => 'Change your cover.',
'controller' => C\Cover::coverSettings($request),
];
return Event::next;
}
/**
* Populate twig vars
*
@ -61,18 +74,14 @@ class Cover extends Plugin
*/
public function onStartTwigPopulateVars(array &$vars): bool
{
$vars['profile_tabs'][] = ['title' => 'Cover',
'route' => 'settings_profile_cover',
];
if (Common::user() != null) {
/*if (Common::user() != null) {
$cover = DB::find('cover', ['gsactor_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;
}

View File

@ -53,7 +53,7 @@ class ProfileColor
*
* @return array template
*/
public function profileColorSettings(Request $request)
public static function profileColorSettings(Request $request)
{
$user = Common::user();
$actor_id = $user->getId();

View File

@ -25,6 +25,8 @@ use App\Core\Event;
use App\Core\Modules\Plugin;
use App\Core\Router\RouteLoader;
use App\Util\Common;
use Plugin\ProfileColor\Controller as C;
use Symfony\Component\HttpFoundation\Request;
/**
* Profile Color plugin main class
@ -51,6 +53,18 @@ class ProfileColor extends Plugin
return Event::next;
}
public function onPopulateProfileSettingsTabs(Request $request, &$tabs)
{
// TODO avatar template shouldn't be on settings folder
$tabs[] = [
'title' => 'Color',
'desc' => 'Change your profile color.',
'controller' => C\ProfileColor::profileColorSettings($request),
];
return Event::next;
}
/**
* Populate twig vars
*
@ -60,9 +74,11 @@ class ProfileColor extends Plugin
*/
public function onStartTwigPopulateVars(array &$vars): bool
{
$vars['profile_tabs'][] = ['title' => 'Color',
'route' => 'settings_profile_color',
];
/*$vars['profile_tabs'][] = [
'title' => 'Color',
'desc' => 'Change your profile color.',
'path' => 'profilecolor/profilecolor.html.twig',
];*/
if (Common::user() != null) {
$color = DB::find('profile_color', ['gsactor_id' => Common::user()->getId()]);
if ($color != null) {

View File

@ -1,19 +1,9 @@
{% extends 'settings/profile.html.twig' %}
<div class='form'>
{{ form(form) }}
</div>
{% block title %}Cover Settings{% endblock %}
{% block body %}
{{ parent() }}
{% endblock body %}
{% block form %}
<div class='form-single'>
{{ form(form) }}
{% if remove_form is not null %}
<div class='form'>
{{ form(remove_form) }}
</div>
{% if remove_form is not null %}
<div class='form-single'>
{{ form(remove_form) }}
</div>
{% endif %}
{% endblock form %}
{% endif %}

View File

@ -1,13 +1,3 @@
{% extends 'settings/profile.html.twig' %}
{% block title %}Profile Color Settings{% endblock %}
{% block body %}
{{ parent() }}
{% endblock body %}
{% block form %}
<div class='form'>
{{ form(form) }}
</div>
{% endblock form %}
<div class='form'>
{{ form(form) }}
</div>

View File

@ -1,23 +1,9 @@
{% extends 'settings/profile.html.twig' %}
{% block title %}Avatar Settings{% endblock %}
{% block stylesheets %}
{{ parent() }}
<div class='form'>
<link href="{{ asset('assets/css/cropperjs/cropper.css') }}" rel="stylesheet">
<script src="{{ asset('assets/javascript/cropperjs/cropper.js') }}"></script>
{% endblock %}
{% block form %}
<div class='form'>
<h1>Settings / Profile</h1>
{{ form(avatar) }}
<div id="img-container">
<img id="img-cropped">
</div>
</div>
{% endblock form %}
{% block javascripts %}
<script type="text/javascript" src="{{ asset('assets/javascript/cropping.js') }}"></script>
{% endblock javascripts %}
{{ form(avatar) }}
<div id="img-container">
<img id="img-cropped">
</div>
</div>

View File

@ -50,15 +50,25 @@
<hr>
<li>
<a href="{{ path('settings_avatar') }}"
class='hover-effect {{ active('settings_avatar') }}'>Avatar</a>
</li>
{% set profile_tabs = handle_event('PopulateProfileSettingsTabs', app.request) %}
{% for tab in profile_tabs %}
<li>
<a href="{{ path(tab['route']) }}"
class='hover-effect {{ active(tab['route']) }}'>{{ tab['title'] }}</a>
<details class="section-title-settings">
<summary>
<h1>{{ tab['title'] }}{{ icon('arrow-down', 'icon icon-details-open') | raw }}</h1>
<em>{{ tab['desc'] }}</em>
</summary>
{% include tab['controller']['_template'] with tab['controller'] only %}
{# <a href="{{ path(tab['route']) }}"
class='hover-effect {{ active(tab['route']) }}'>{{ tab['title'] }}</a> #}
</details>
</li>
<hr>
{% endfor %}
</ul>
</nav>

View File

@ -29,9 +29,9 @@
<h2>{{ 'Followed' | trans }} {{ user_followed }}</h2>
</span>
{% for extra in profile_extras %}
{# {% for extra in profile_extras %}
{% include '/'~ extra.name ~ '/view.html.twig' with {'vars': extra.vars} only %}
{% endfor %}
{% endfor %} #}
</section>
<nav>