[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 committed by Hugo Sales
parent 6dd0292397
commit c8a8e94d48
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
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\GSFile;
use App\Core\Modules\Component; use App\Core\Modules\Component;
use App\Util\Common; use App\Util\Common;
use Component\Avatar\Controller as C;
use Component\Avatar\Exception\NoAvatarException; use Component\Avatar\Exception\NoAvatarException;
use Exception; use Exception;
use Symfony\Component\Asset\Package; use Symfony\Component\Asset\Package;
use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy; use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;
use Symfony\Component\HttpFoundation\Request;
class Avatar extends Component class Avatar extends Component
{ {
@ -39,7 +41,18 @@ class Avatar extends Component
return Event::next; 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) { if (Common::user() != null) {
$vars['user_avatar'] = self::getAvatarUrl(); $vars['user_avatar'] = self::getAvatarUrl();

View File

@ -59,7 +59,7 @@ class Avatar extends Controller
/** /**
* Local user avatar panel * Local user avatar panel
*/ */
public function settings_avatar(Request $request) public static function settings_avatar(Request $request)
{ {
$form = Form::create([ $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]],

View File

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

View File

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

View File

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

View File

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

View File

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

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'> <div class='form'>
{{ form(form) }} {{ form(form) }}
</div> </div>
{% endblock form %}

View File

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

View File

@ -50,15 +50,25 @@
<hr> <hr>
<li> {% set profile_tabs = handle_event('PopulateProfileSettingsTabs', app.request) %}
<a href="{{ path('settings_avatar') }}"
class='hover-effect {{ active('settings_avatar') }}'>Avatar</a>
</li>
{% for tab in profile_tabs %} {% for tab in profile_tabs %}
<li> <li>
<a href="{{ path(tab['route']) }}" <details class="section-title-settings">
class='hover-effect {{ active(tab['route']) }}'>{{ tab['title'] }}</a> <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> </li>
<hr>
{% endfor %} {% endfor %}
</ul> </ul>
</nav> </nav>

View File

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