[PLUGINS][ProfileColor] Current color is now selected by default. Not found exception is now handled.
This commit is contained in:
parent
a681acae67
commit
7b8eb3fda9
|
@ -23,6 +23,8 @@ namespace Plugin\ProfileColor\Controller;
|
||||||
|
|
||||||
use App\Core\DB\DB;
|
use App\Core\DB\DB;
|
||||||
use App\Core\Form;
|
use App\Core\Form;
|
||||||
|
use App\Util\Exception\DuplicateFoundException;
|
||||||
|
use App\Util\Exception\NotFoundException;
|
||||||
use App\Util\Exception\ServerException;
|
use App\Util\Exception\ServerException;
|
||||||
use function App\Core\I18n\_m;
|
use function App\Core\I18n\_m;
|
||||||
use App\Util\Common;
|
use App\Util\Common;
|
||||||
|
@ -56,14 +58,15 @@ class ProfileColor
|
||||||
*/
|
*/
|
||||||
public static function profileColorSettings(Request $request)
|
public static function profileColorSettings(Request $request)
|
||||||
{
|
{
|
||||||
$user = Common::user();
|
$actor = Common::actor();
|
||||||
$actor_id = $user->getId();
|
$actor_id = $actor->getId();
|
||||||
$pcolor = DB::findOneBy('profile_color', ['actor_id' => $actor_id]);
|
|
||||||
|
$current_profile_color = DB::find('profile_color', ['actor_id' => $actor_id]);
|
||||||
|
|
||||||
$form = Form::create([
|
$form = Form::create([
|
||||||
['color', ColorType::class, [
|
['color', ColorType::class, [
|
||||||
'html5' => true,
|
'html5' => true,
|
||||||
'data' => "#000000",
|
'data' => $current_profile_color ? $current_profile_color->getColor() : "#000000",
|
||||||
'label' => _m('Profile Color'),
|
'label' => _m('Profile Color'),
|
||||||
'help' => _m('Choose your Profile Color')]
|
'help' => _m('Choose your Profile Color')]
|
||||||
],
|
],
|
||||||
|
@ -75,14 +78,14 @@ class ProfileColor
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
|
|
||||||
if ($pcolor !== null) {
|
if ($current_profile_color !== null) {
|
||||||
DB::remove($pcolor);
|
DB::remove($current_profile_color);
|
||||||
DB::flush();
|
DB::flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $form->getData();
|
$data = $form->getData();
|
||||||
$pcolor = Entity\ProfileColor::create(['actor_id' => $actor_id, 'color' => $data['color']]);
|
$current_profile_color = Entity\ProfileColor::create(['actor_id' => $actor_id, 'color' => $data['color']]);
|
||||||
DB::persist($pcolor);
|
DB::persist($current_profile_color);
|
||||||
DB::flush();
|
DB::flush();
|
||||||
|
|
||||||
throw new RedirectException();
|
throw new RedirectException();
|
||||||
|
|
|
@ -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 App\Util\Exception\DuplicateFoundException;
|
||||||
|
use App\Util\Exception\NotFoundException;
|
||||||
use App\Util\Exception\RedirectException;
|
use App\Util\Exception\RedirectException;
|
||||||
use App\Util\Exception\ServerException;
|
use App\Util\Exception\ServerException;
|
||||||
use App\Util\Formatting;
|
use App\Util\Formatting;
|
||||||
|
@ -83,13 +85,18 @@ class ProfileColor extends Plugin
|
||||||
* @param $res
|
* @param $res
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function onAppendCardProfile($vars, &$res): bool
|
public function onAppendCardProfile(&$res): bool
|
||||||
{
|
{
|
||||||
$actor = $vars['actor'];
|
$actor = Common::actor();
|
||||||
if ($actor !== null) {
|
if ($actor !== null) {
|
||||||
$actor_id = $actor->getId();
|
$actor_id = $actor->getId();
|
||||||
|
|
||||||
$color = DB::find('profile_color', ['actor_id' => $actor_id]);
|
try {
|
||||||
|
$color = DB::findOneBy('profile_color', ['actor_id' => $actor_id]);
|
||||||
|
} catch (NotFoundException $e) {
|
||||||
|
return Event::next;
|
||||||
|
}
|
||||||
|
|
||||||
if ($color !== null) {
|
if ($color !== null) {
|
||||||
$res[] = Formatting::twigRenderFile('/profileColor/profileColorView.html.twig', ['profile_color' => $color, 'actor' => $actor_id]);
|
$res[] = Formatting::twigRenderFile('/profileColor/profileColorView.html.twig', ['profile_color' => $color, 'actor' => $actor_id]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -659,6 +659,13 @@ input[type=checkbox] {
|
||||||
mask-image: url("../icons/check-off.svg") !important;
|
mask-image: url("../icons/check-off.svg") !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input[type=color] {
|
||||||
|
border: unset;
|
||||||
|
padding: 2px;
|
||||||
|
width: 100%;
|
||||||
|
height: 3rem;
|
||||||
|
}
|
||||||
|
|
||||||
/* DISABLED STATE TEXT COLOR */
|
/* DISABLED STATE TEXT COLOR */
|
||||||
:is(:disabled, :disabled:active)::file-selector-button,
|
:is(:disabled, :disabled:active)::file-selector-button,
|
||||||
button:is(:disabled, :disabled:active),
|
button:is(:disabled, :disabled:active),
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
{% for block in handle_event('AppendCardProfile', {'actor': actor}) %}
|
{% for block in handle_event('AppendCardProfile') %}
|
||||||
{{ block | raw }}
|
{{ block | raw }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</section>
|
</section>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user