Browse Source

implement theme settings #17

main
ghost 1 year ago
parent
commit
5a940541ee
  1. 3
      .env
  2. 1
      config/packages/twig.yaml
  3. 2
      config/services.yaml
  4. 12
      src/Controller/UserController.php
  5. 15
      src/Entity/User.php
  6. 3
      src/Service/UserService.php
  7. 4
      templates/default/layout.html.twig
  8. 18
      templates/default/user/profile.html.twig

3
.env

@ -52,6 +52,9 @@ APP_NAME=YGGtracker @@ -52,6 +52,9 @@ APP_NAME=YGGtracker
APP_LOCALE=en
APP_LOCALES=en|cs|eo|fr|ka|de|he|it|lv|pl|pt|ru|es|uk
APP_THEME=default
APP_THEMES=default
APP_TRACKERS=http://[201:23b4:991a:634d:8359:4521:5576:15b7]:2023/announce|http://[200:1e2f:e608:eb3a:2bf:1e62:87ba:e2f7]/announce|http://[316:c51a:62a3:8b9::5]/announce
APP_PAGE_TITLE_LENGTH_MIN=10

1
config/packages/twig.yaml

@ -3,6 +3,7 @@ twig: @@ -3,6 +3,7 @@ twig:
globals:
version: '%app.version%'
name: '%app.name%'
theme: '%app.theme%'
when@test:
twig:

2
config/services.yaml

@ -8,6 +8,8 @@ parameters: @@ -8,6 +8,8 @@ parameters:
app.name: '%env(APP_NAME)%'
app.locale: '%env(APP_LOCALE)%'
app.locales: '%env(APP_LOCALES)%'
app.theme: '%env(APP_THEME)%'
app.themes: '%env(APP_THEMES)%'
app.trackers: '%env(APP_TRACKERS)%'
app.page.title.length.min: '%env(APP_PAGE_TITLE_LENGTH_MIN)%'
app.page.title.length.max: '%env(APP_PAGE_TITLE_LENGTH_MAX)%'

12
src/Controller/UserController.php

@ -134,6 +134,14 @@ class UserController extends AbstractController @@ -134,6 +134,14 @@ class UserController extends AbstractController
);
}
// Update theme
if (in_array($request->get('theme'), explode('|', $this->getParameter('app.themes'))))
{
$user->setTheme(
$request->get('theme')
);
}
// Save changes to DB
$userService->save($user);
@ -158,13 +166,15 @@ class UserController extends AbstractController @@ -158,13 +166,15 @@ class UserController extends AbstractController
'status' => $user->isStatus(),
'locale' => $user->getLocale(),
'locales' => $user->getLocales(),
'theme' => $user->getTheme(),
'added' => $user->getAdded(),
'identicon' => $userService->identicon(
$user->getAddress(),
48
),
],
'locales' => explode('|', $this->getParameter('app.locales'))
'locales' => explode('|', $this->getParameter('app.locales')),
'themes' => explode('|', $this->getParameter('app.themes'))
]
);
}

15
src/Entity/User.php

@ -35,6 +35,9 @@ class User @@ -35,6 +35,9 @@ class User
#[ORM\Column(type: Types::ARRAY)]
private array $locales = [];
#[ORM\Column(length: 255)]
private ?string $theme = null;
public function getId(): ?int
{
return $this->id;
@ -130,4 +133,16 @@ class User @@ -130,4 +133,16 @@ class User
return $this;
}
public function getTheme(): ?string
{
return $this->theme;
}
public function setTheme(string $theme): static
{
$this->theme = $theme;
return $this;
}
}

3
src/Service/UserService.php

@ -47,6 +47,9 @@ class UserService @@ -47,6 +47,9 @@ class UserService
$user->setLocales(
explode('|', $this->parameterBagInterface->get('app.locales'))
);
$user->setTheme(
$this->parameterBagInterface->get('app.theme')
);
$this->save($user);

4
templates/default/layout.html.twig

@ -4,8 +4,8 @@ @@ -4,8 +4,8 @@
<meta charset="UTF-8" />
<title>{% block title %}{{ name }}{% endblock %}</title>
{% block stylesheets %}
<link href="{{ asset('asset/default/css/framework.css') }}?{{ version }}" rel="stylesheet" />
<link href="{{ asset('asset/default/css/common.css') }}?{{ version }}" rel="stylesheet" />
<link href="{{ asset('asset/' ~ theme ~ '/css/framework.css') }}?{{ version }}" rel="stylesheet" />
<link href="{{ asset('asset/' ~ theme ~ '/css/common.css') }}?{{ version }}" rel="stylesheet" />
{% endblock %}
</head>
<body>

18
templates/default/user/profile.html.twig

@ -101,6 +101,24 @@ @@ -101,6 +101,24 @@
{% endfor %}
</td>
</tr>
<tr>
<td class="padding-t-16-px">{{ 'Theme'|trans }}</td>
<td class="padding-t-16-px">
<select name="theme">
{% for theme in themes %}
{% if theme == user.theme %}
<option value="{{ theme }}" selected="selected">
{{ theme }}
</option>
{% else %}
<option value="{{ theme }}">
{{ theme }}
</option>
{% endif %}
{% endfor %}
</select>
</td>
</tr>
</tbody>
</table>
<div class="text-right">

Loading…
Cancel
Save