From c8a8e94d48e1d680c99bf9940445346b8cce0ade Mon Sep 17 00:00:00 2001 From: Eliseu Amaro Date: Thu, 29 Jul 2021 20:20:32 +0100 Subject: [PATCH] [SETTINGS][PLUGIN][CONTROLLER] Populate profile tabs event added. Settings base template populated with such event for plugins and components. Signed-off-by: Eliseu Amaro --- components/Avatar/Avatar.php | 15 +++++++++- components/Avatar/Controller/Avatar.php | 8 +++--- plugins/Cover/Controller/Cover.php | 6 ++-- plugins/Cover/Cover.php | 21 ++++++++++---- .../ProfileColor/Controller/ProfileColor.php | 2 +- plugins/ProfileColor/ProfileColor.php | 22 +++++++++++++-- templates/cover/cover.html.twig | 24 +++++----------- templates/profilecolor/profilecolor.html.twig | 16 ++--------- templates/settings/avatar.html.twig | 28 +++++-------------- templates/settings/base.html.twig | 22 +++++++++++---- templates/sidepanel/left/left.html.twig | 4 +-- 11 files changed, 91 insertions(+), 77 deletions(-) diff --git a/components/Avatar/Avatar.php b/components/Avatar/Avatar.php index 0a97374d3c..0dd49f9ba6 100644 --- a/components/Avatar/Avatar.php +++ b/components/Avatar/Avatar.php @@ -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(); diff --git a/components/Avatar/Controller/Avatar.php b/components/Avatar/Controller/Avatar.php index 432f269a5e..5d81b7fce5 100644 --- a/components/Avatar/Controller/Avatar.php +++ b/components/Avatar/Controller/Avatar.php @@ -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); diff --git a/plugins/Cover/Controller/Cover.php b/plugins/Cover/Controller/Cover.php index a9dbe90c11..4ef037df75 100644 --- a/plugins/Cover/Controller/Cover.php +++ b/plugins/Cover/Controller/Cover.php @@ -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' => [ diff --git a/plugins/Cover/Cover.php b/plugins/Cover/Cover.php index 20703fe4c8..d380b343fe 100644 --- a/plugins/Cover/Cover.php +++ b/plugins/Cover/Cover.php @@ -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; } diff --git a/plugins/ProfileColor/Controller/ProfileColor.php b/plugins/ProfileColor/Controller/ProfileColor.php index dcc7118cf4..0011d154ca 100644 --- a/plugins/ProfileColor/Controller/ProfileColor.php +++ b/plugins/ProfileColor/Controller/ProfileColor.php @@ -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(); diff --git a/plugins/ProfileColor/ProfileColor.php b/plugins/ProfileColor/ProfileColor.php index 077de90a2c..8a3069e5b2 100644 --- a/plugins/ProfileColor/ProfileColor.php +++ b/plugins/ProfileColor/ProfileColor.php @@ -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) { diff --git a/templates/cover/cover.html.twig b/templates/cover/cover.html.twig index ef062ea42a..ca64c39e69 100644 --- a/templates/cover/cover.html.twig +++ b/templates/cover/cover.html.twig @@ -1,19 +1,9 @@ -{% extends 'settings/profile.html.twig' %} +
+ {{ form(form) }} +
-{% block title %}Cover Settings{% endblock %} - -{% block body %} - {{ parent() }} -{% endblock body %} - -{% block form %} -
- {{ form(form) }} +{% if remove_form is not null %} +
+ {{ form(remove_form) }}
- - {% if remove_form is not null %} -
- {{ form(remove_form) }} -
- {% endif %} -{% endblock form %} \ No newline at end of file +{% endif %} \ No newline at end of file diff --git a/templates/profilecolor/profilecolor.html.twig b/templates/profilecolor/profilecolor.html.twig index 71b28ac853..ca9a027941 100644 --- a/templates/profilecolor/profilecolor.html.twig +++ b/templates/profilecolor/profilecolor.html.twig @@ -1,13 +1,3 @@ -{% extends 'settings/profile.html.twig' %} - -{% block title %}Profile Color Settings{% endblock %} - -{% block body %} - {{ parent() }} -{% endblock body %} - -{% block form %} -
- {{ form(form) }} -
-{% endblock form %} \ No newline at end of file +
+ {{ form(form) }} +
\ No newline at end of file diff --git a/templates/settings/avatar.html.twig b/templates/settings/avatar.html.twig index 7309c70682..24ce565df4 100644 --- a/templates/settings/avatar.html.twig +++ b/templates/settings/avatar.html.twig @@ -1,23 +1,9 @@ -{% extends 'settings/profile.html.twig' %} - -{% block title %}Avatar Settings{% endblock %} - -{% block stylesheets %} - {{ parent() }} +
- -{% endblock %} - -{% block form %} -
-

Settings / Profile

- {{ form(avatar) }} -
- -
-
-{% endblock form %} - -{% block javascripts %} -{% endblock javascripts %} + + {{ form(avatar) }} +
+ +
+
diff --git a/templates/settings/base.html.twig b/templates/settings/base.html.twig index 2e1d3910da..2e3b5a965e 100644 --- a/templates/settings/base.html.twig +++ b/templates/settings/base.html.twig @@ -50,15 +50,25 @@
-
  • - Avatar -
  • + {% set profile_tabs = handle_event('PopulateProfileSettingsTabs', app.request) %} {% for tab in profile_tabs %}
  • - {{ tab['title'] }} +
    + +

    {{ tab['title'] }}{{ icon('arrow-down', 'icon icon-details-open') | raw }}

    + + {{ tab['desc'] }} +
    + + {% include tab['controller']['_template'] with tab['controller'] only %} + + {# {{ tab['title'] }} #} + +
  • + +
    {% endfor %} diff --git a/templates/sidepanel/left/left.html.twig b/templates/sidepanel/left/left.html.twig index 0ae0a1727c..0a54cee592 100644 --- a/templates/sidepanel/left/left.html.twig +++ b/templates/sidepanel/left/left.html.twig @@ -29,9 +29,9 @@

    {{ 'Followed' | trans }} {{ user_followed }}

    - {% for extra in profile_extras %} + {# {% for extra in profile_extras %} {% include '/'~ extra.name ~ '/view.html.twig' with {'vars': extra.vars} only %} - {% endfor %} + {% endfor %} #}