mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Allow a user to change and remove his profile picture from user settings.
This commit is contained in:
parent
04b99cd247
commit
0063d360ce
4 changed files with 60 additions and 1 deletions
|
@ -245,6 +245,16 @@ class UserSettingsController extends AbstractController
|
|||
//$em->flush();
|
||||
//For some reason the avatar is not set as master picture attachment, so we do it again here
|
||||
$user->setMasterPictureAttachment($attachment);
|
||||
$page_need_reload = true;
|
||||
}
|
||||
|
||||
if ($form->getClickedButton() && 'remove_avatar' === $form->getClickedButton()->getName()) {
|
||||
//Remove the avatar attachment from the user if requested
|
||||
if ($user->getMasterPictureAttachment() !== null) {
|
||||
$em->remove($user->getMasterPictureAttachment());
|
||||
$user->setMasterPictureAttachment(null);
|
||||
$page_need_reload = true;
|
||||
}
|
||||
}
|
||||
|
||||
$em->flush();
|
||||
|
|
|
@ -25,6 +25,7 @@ namespace App\Form;
|
|||
use App\Entity\UserSystem\User;
|
||||
use App\Form\Type\CurrencyEntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Event\PreSetDataEvent;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FileType;
|
||||
|
@ -34,6 +35,7 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
|||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\Validator\Constraints\File;
|
||||
|
@ -77,9 +79,10 @@ class UserSettingsType extends AbstractType
|
|||
'disabled' => !$this->security->isGranted('edit_infos', $options['data']) || $this->demo_mode,
|
||||
])
|
||||
->add('avatar_file', FileType::class, [
|
||||
'label' => 'user.change_avatar.label',
|
||||
'label' => 'user_settings.change_avatar.label',
|
||||
'mapped' => false,
|
||||
'required' => false,
|
||||
'disabled' => !$this->security->isGranted('edit_infos', $options['data']) || $this->demo_mode,
|
||||
'attr' => [
|
||||
'accept' => 'image/*',
|
||||
],
|
||||
|
@ -134,6 +137,25 @@ class UserSettingsType extends AbstractType
|
|||
//Buttons
|
||||
->add('save', SubmitType::class, ['label' => 'save'])
|
||||
->add('reset', ResetType::class, ['label' => 'reset']);
|
||||
|
||||
//Add the remove_avatar button if the user has an avatar (we have to add this dynamically)
|
||||
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (PreSetDataEvent $event) {
|
||||
$data = $event->getData();
|
||||
if (!$data instanceof User) {
|
||||
return;
|
||||
}
|
||||
$form = $event->getForm();
|
||||
|
||||
//if ($data->getMasterPictureAttachment()) {
|
||||
$form->add('remove_avatar', SubmitType::class, [
|
||||
'label' => 'user_settings.remove_avatar.label',
|
||||
'disabled' => !$this->security->isGranted('edit_infos', $data) || $this->demo_mode,
|
||||
'attr' => [
|
||||
'class' => 'btn btn-link',
|
||||
],
|
||||
]);
|
||||
//}
|
||||
});
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
|
|
|
@ -25,6 +25,15 @@
|
|||
{{ form_row(settings_form.last_name) }}
|
||||
{{ form_row(settings_form.department) }}
|
||||
{{ form_row(settings_form.email) }}
|
||||
{{ form_row(settings_form.avatar_file) }}
|
||||
<div class="mb-3 row {% if user.masterPictureAttachment is null %}d-none{% endif %}">
|
||||
<div class="offset-sm-3 col-sm-9">
|
||||
{% if user.masterPictureAttachment %}
|
||||
<img src="{{ attachment_thumbnail(user.masterPictureAttachment, 'thumbnail_md') }}" alt="avatar" class="rounded" style="height: 75px;">
|
||||
{% endif %}
|
||||
{{ form_widget(settings_form.remove_avatar) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="configuration" role="tabpanel" aria-labelledby="profile-tab">
|
||||
{{ form_row(settings_form.language) }}
|
||||
|
|
|
@ -10399,5 +10399,23 @@ Element 3</target>
|
|||
<target>Number of stocked builds</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="Mken7uv" name="user.change_avatar.label">
|
||||
<segment>
|
||||
<source>user.change_avatar.label</source>
|
||||
<target>Change profile picture</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="QFNPD0_" name="user_settings.change_avatar.label">
|
||||
<segment>
|
||||
<source>user_settings.change_avatar.label</source>
|
||||
<target>Change profile picture</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="GLYVqz2" name="user_settings.remove_avatar.label">
|
||||
<segment>
|
||||
<source>user_settings.remove_avatar.label</source>
|
||||
<target>Remove profile picture</target>
|
||||
</segment>
|
||||
</unit>
|
||||
</file>
|
||||
</xliff>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue