Ver código fonte

[PLUGINS][ProfileColor] Settings page render problem fixed. ColorType given data wasn't a string.

remotes/upstream/experimental
Eliseu Amaro 1 ano atrás
pai
commit
808da203ad
7 arquivos alterados com 44 adições e 31 exclusões
  1. +1
    -1
      plugins/Cover/Controller/Cover.php
  2. +3
    -3
      plugins/Cover/templates/cover/cover.html.twig
  3. +20
    -16
      plugins/ProfileColor/Controller/ProfileColor.php
  4. +15
    -6
      plugins/ProfileColor/ProfileColor.php
  5. +1
    -1
      plugins/ProfileColor/templates/profileColor/profileColorSettings.html.twig
  6. +2
    -2
      plugins/ProfileColor/templates/profileColor/profileColorView.html.twig
  7. +2
    -2
      templates/cards/profile/view.html.twig

+ 1
- 1
plugins/Cover/Controller/Cover.php Ver arquivo

@@ -133,7 +133,7 @@ class Cover
}
$removeForm = $form2->createView();
}
return ['_template' => 'cover/cover.html.twig', 'form' => $form->createView(), 'remove_form' => $removeForm];
return ['_template' => 'cover/cover.html.twig', 'cover' => $form->createView(), 'cover_remove_form' => $removeForm];
}

/**


+ 3
- 3
plugins/Cover/templates/cover/cover.html.twig Ver arquivo

@@ -1,9 +1,9 @@
<div class='form'>
{{ form(form) }}
{{ form(cover) }}
</div>

{% if remove_form is not null %}
{% if cover_remove_form is not null %}
<div class='form'>
{{ form(remove_form) }}
{{ form(cover_remove_form) }}
</div>
{% endif %}

+ 20
- 16
plugins/ProfileColor/Controller/ProfileColor.php Ver arquivo

@@ -23,6 +23,7 @@ namespace Plugin\ProfileColor\Controller;

use App\Core\DB\DB;
use App\Core\Form;
use App\Util\Exception\ServerException;
use function App\Core\I18n\_m;
use App\Util\Common;
use App\Util\Exception\RedirectException;
@@ -39,51 +40,54 @@ use Symfony\Component\HttpFoundation\Request;
* @category ProfileColor
*
* @author Daniel Brandao <up201705812@fe.up.pt>
* @author Eliseu Amaro <mail@eliseuama.ro>
* @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class ProfileColor
{

/**
* Add/change profile color
*
* Change Profile color background
* @param Request $request
*
* @return array
* @throws RedirectException
*
* @return array template
* @throws ServerException
*/
public static function profileColorSettings(Request $request)
{
$user = Common::user();
$actor_id = $user->getId();
$pcolor = DB::find('profile_color', ['actor_id' => $actor_id]);
$color = '#000000';
if ($pcolor != null) {
$color = $pcolor;
}
$user = Common::user();
$actor_id = $user->getId();
$pcolor = DB::findOneBy('profile_color', ['actor_id' => $actor_id]);

$form = Form::create([
['color', ColorType::class, ['data' => $color, 'label' => _m('Profile Color'), 'help' => _m('Choose your Profile Color')] ],
['color', ColorType::class, [
'html5' => true,
'data' => "#000000",
'label' => _m('Profile Color'),
'help' => _m('Choose your Profile Color')]
],
['hidden', HiddenType::class, []],
['save_profile_color', SubmitType::class, ['label' => _m('Submit')]],
]);

$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();

if ($pcolor !== null) {
DB::remove($pcolor);
DB::flush();
}

$pcolor = Entity\ProfileColor::create(['actor_id' => $actor_id, 'profile_color' => $data['color']]);
$data = $form->getData();
$pcolor = Entity\ProfileColor::create(['actor_id' => $actor_id, 'color' => $data['color']]);
DB::persist($pcolor);
DB::flush();

throw new RedirectException();
}

return ['_template' => 'profileColor/profileColorSettings.html.twig', 'form' => $form->createView()];
return ['_template' => 'profileColor/profileColorSettings.html.twig', 'profile_color' => $form->createView()];
}
}

+ 15
- 6
plugins/ProfileColor/ProfileColor.php Ver arquivo

@@ -25,6 +25,8 @@ use App\Core\Event;
use App\Core\Modules\Plugin;
use App\Core\Router\RouteLoader;
use App\Util\Common;
use App\Util\Exception\RedirectException;
use App\Util\Exception\ServerException;
use App\Util\Formatting;
use Plugin\ProfileColor\Controller as C;
use Symfony\Component\HttpFoundation\Request;
@@ -50,10 +52,17 @@ class ProfileColor extends Plugin
*/
public function onAddRoute(RouteLoader $r): bool
{
$r->connect('settings_profile_color', 'settings/color', [Controller\ProfileColor::class, 'profilecolorsettings']);
$r->connect('settings_profile_color', 'settings/color', [Controller\ProfileColor::class, 'profileColorSettings']);
return Event::next;
}

/**
* @param Request $request
* @param $tabs
* @return bool
* @throws RedirectException
* @throws ServerException
*/
public function onPopulateProfileSettingsTabs(Request $request, &$tabs)
{
// TODO avatar template shouldn't be on settings folder
@@ -74,15 +83,15 @@ class ProfileColor extends Plugin
* @param $res
* @return bool
*/
public function onAppendCardProfile(&$res): bool
public function onAppendCardProfile($vars, &$res): bool
{
$user = Common::user();
if ($user !== null) {
$actor_id = $user->getId();
$actor = $vars['actor'];
if ($actor !== null) {
$actor_id = $actor->getId();

$color = DB::find('profile_color', ['actor_id' => $actor_id]);
if ($color !== null) {
$res[] = Formatting::twigRenderFile('/profileColor/profileColorView.html.twig', ['profile' => $color]);
$res[] = Formatting::twigRenderFile('/profileColor/profileColorView.html.twig', ['profile_color' => $color, 'actor' => $actor_id]);
}
}



+ 1
- 1
plugins/ProfileColor/templates/profileColor/profileColorSettings.html.twig Ver arquivo

@@ -1,3 +1,3 @@
<div class='form'>
{{ form(form) }}
{{ form(profile_color) }}
</div>

+ 2
- 2
plugins/ProfileColor/templates/profileColor/profileColorView.html.twig Ver arquivo

@@ -1,7 +1,7 @@
{% block stylesheets %}
<style>
.profile {
background: {{ profile.color }} !important;
#profile-{{ actor }} {
background: {{ profile_color.color }} !important;
}
</style>
{% endblock stylesheets %}

+ 2
- 2
templates/cards/profile/view.html.twig Ver arquivo

@@ -4,7 +4,7 @@
{% set actor_bio = actor.getBio() %}

{% block profile_view %}
<section class='profile' title="{{ actor_nickname }}'s {{ 'profile information.' | trans }}">
<section id='profile-{{ actor.id }}' class='profile' title="{{ actor_nickname }}'s {{ 'profile information.' | trans }}">
<a href="{{ path('actor_view_nickname', {'nickname' : actor_nickname}) }}">
<div class="profile-info">
<img src='{{ actor_avatar }}' class="profile-avatar" alt="{{ actor_nickname }}{{ '\'s avatar.' | trans }}">
@@ -35,7 +35,7 @@
{% endif %}
</nav>

{% for block in handle_event('AppendCardProfile') %}
{% for block in handle_event('AppendCardProfile', {'actor': actor}) %}
{{ block | raw }}
{% endfor %}
</section>


Carregando…
Cancelar
Salvar