Skip to content

Commit 956a2dd

Browse files
committed
Add field to display settings image in background
1 parent d7b1cb7 commit 956a2dd

File tree

6 files changed

+53
-33
lines changed

6 files changed

+53
-33
lines changed

src/Form/Type/Settings/AdminSettingsType.php

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,6 @@ class AdminSettingsType extends AbstractSettingsType implements SettingsTypeInte
2828
*/
2929
public function buildForm(FormBuilderInterface $builder, array $options): void
3030
{
31-
$this->addWithDefaultCheckbox(
32-
$builder,
33-
'color',
34-
ColorType::class,
35-
[
36-
'label' => 'monsieurbiz_better_admin.form.color',
37-
'help' => 'monsieurbiz_better_admin.form.color_help',
38-
'required' => false,
39-
]
40-
);
41-
$this->addWithDefaultCheckbox(
42-
$builder,
43-
'circular_icon_color',
44-
ColorType::class,
45-
[
46-
'label' => 'monsieurbiz_better_admin.form.circular_icon_color',
47-
'help' => 'monsieurbiz_better_admin.form.circular_icon_color_help',
48-
'required' => false,
49-
]
50-
);
5131
$this->addWithDefaultCheckbox(
5232
$builder,
5333
'logo',
@@ -90,21 +70,40 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
9070
);
9171
$this->addWithDefaultCheckbox(
9272
$builder,
93-
'custom_css',
94-
TextareaType::class,
73+
'background_image',
74+
ImageType::class,
9575
[
96-
'label' => 'monsieurbiz_better_admin.form.custom_css',
97-
'help' => 'monsieurbiz_better_admin.form.custom_css_help',
76+
'label' => 'monsieurbiz_better_admin.form.background_image',
9877
'required' => false,
9978
]
10079
);
10180
$this->addWithDefaultCheckbox(
10281
$builder,
103-
'background_image_keywords',
104-
TextType::class,
82+
'color',
83+
ColorType::class,
84+
[
85+
'label' => 'monsieurbiz_better_admin.form.color',
86+
'help' => 'monsieurbiz_better_admin.form.color_help',
87+
'required' => false,
88+
]
89+
);
90+
$this->addWithDefaultCheckbox(
91+
$builder,
92+
'circular_icon_color',
93+
ColorType::class,
10594
[
106-
'label' => 'monsieurbiz_better_admin.form.background_image_keywords',
107-
'help' => 'monsieurbiz_better_admin.form.background_image_keywords_help',
95+
'label' => 'monsieurbiz_better_admin.form.circular_icon_color',
96+
'help' => 'monsieurbiz_better_admin.form.circular_icon_color_help',
97+
'required' => false,
98+
]
99+
);
100+
$this->addWithDefaultCheckbox(
101+
$builder,
102+
'custom_css',
103+
TextareaType::class,
104+
[
105+
'label' => 'monsieurbiz_better_admin.form.custom_css',
106+
'help' => 'monsieurbiz_better_admin.form.custom_css_help',
108107
'required' => false,
109108
]
110109
);

src/Resources/config/monsieurbiz/settings.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ monsieurbiz_sylius_settings:
1313
circular_icon_color: '#ffffff'
1414
logo_login_width: '200'
1515
logo_sidebar_width: '90'
16-
background_image_keywords: 'computer,typing,editor'

src/Resources/config/sylius/images.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ liip_imagine:
88
filters:
99
relative_resize:
1010
widen: 250
11+
admin_login_background:
12+
filters:
13+
relative_resize:
14+
widen: 1600

src/Resources/translations/messages.en.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ monsieurbiz_better_admin:
1414
logo_sidebar_help: 'Displayed in sidebar (in dark background)'
1515
logo_sidebar_width: 'Logo width in sidebar'
1616
logo_sidebar_width_help: 'Width of the logo in the sidebar in pixels'
17-
background_image_keywords: 'Background image keywords in login page'
18-
background_image_keywords_help: 'Keywords to search a background image in Unsplash'
17+
background_image: 'Background image of the login page'
1918
settings:
2019
admin:
2120
plugin_name: Admin

src/Resources/translations/messages.fr.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ monsieurbiz_better_admin:
1414
logo_sidebar_help: 'Affiché dans la barre latérale (sur fond sombre)'
1515
logo_sidebar_width: 'Largeur du logo dans la barre latérale'
1616
logo_sidebar_width_help: 'Largeur du logo dans la barre latérale en pixels'
17-
background_image_keywords: 'Mots-clés de l''image de fond dans la page de connexion'
18-
background_image_keywords_help: 'Mots-clés pour rechercher une image de fond dans Unsplash'
17+
background_image: 'Image de fond de la page de connexion'
1918
settings:
2019
admin:
2120
plugin_name: Admin

src/Resources/views/SyliusUiBundle/Security/_login.html.twig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
{% import '@SyliusUi/Macro/messages.html.twig' as messages %}
44

55
{% set logo = setting('monsieurbiz_better_admin.admin', 'logo')|default('') %}
6+
{% set backgroundImage = setting('monsieurbiz_better_admin.admin', 'background_image')|default('') %}
7+
68
<div class="ui middle aligned center aligned grid">
79
<div class="right floated column" style="margin-right: 2%;">
810
{{ sonata_block_render_event('sylius.admin.login.before_form', {'form': form}) }}
@@ -35,3 +37,21 @@
3537
{{ form_end(form, {'render_rest': false}) }}
3638
</div>
3739
</div>
40+
41+
<script type="text/javascript">
42+
function changeBodyBackground(imgUrl)
43+
{
44+
let bodyStyle = document.body.style;
45+
bodyStyle.backgroundSize = 'cover';
46+
bodyStyle.backgroundRepeat = 'no-repeat';
47+
bodyStyle.backgroundImage = "url('" + imgUrl + "')";
48+
}
49+
50+
document.addEventListener('DOMContentLoaded', function() {
51+
{% if backgroundImage is empty %}
52+
changeBodyBackground('https://picsum.photos/1600/900?random');
53+
{% else %}
54+
changeBodyBackground('{{ asset(backgroundImage) | imagine_filter('admin_login_background') | escape('js') }}');
55+
{% endif %}
56+
});
57+
</script>

0 commit comments

Comments
 (0)