Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "OSL-3.0",
"require": {
"php": ">=8.4",
"forumify/forumify-platform": "^1.0",
"forumify/forumify-platform": "^1.0.7",
"deschutesdesigngroupllc/perscom-php-sdk": "3.0.0",
"league/commonmark": "^2.5"
},
Expand Down
29 changes: 29 additions & 0 deletions migrations/Version20260115160839.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace ForumifyPerscomPluginMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20260115160839 extends AbstractMigration
{
public function getDescription(): string
{
return 'add option to control name on enlistment form';
}

public function up(Schema $schema): void
{
$this->addSql('INSERT INTO setting (`key`, `value`) VALUES (?, ?)', [
'perscom.enlistment.roleplay_names',
'true',
]);
}

public function down(Schema $schema): void
{
$this->addSql('DELETE FROM setting WHERE `key` = ?', ['perscom.enlistment.roleplay_names']);
}
}
5 changes: 5 additions & 0 deletions src/Admin/Form/ConfigurationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'placeholder' => 'Select a form to use for enlistments',
'required' => false,
])
->add('perscom__enlistment__roleplay_names', CheckboxType::class, [
'required' => false,
'label' => 'Require roleplay friendly name',
'help' => 'When enabled, the enlistment form will show "firstname" and "lastname". Otherwise, it will use the logged in user\'s forum display name.',
])
->add('perscom__enlistment__forum', ChoiceType::class, [
'autocomplete' => true,
'choices' => $this->getForumChoices(),
Expand Down
11 changes: 6 additions & 5 deletions src/Forum/Controller/UserEnlistController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Forumify\PerscomPlugin\Forum\Controller;

use Forumify\Core\Entity\User;
use Forumify\PerscomPlugin\Forum\Form\Enlistment;
use Forumify\Core\Repository\SettingRepository;
use Forumify\PerscomPlugin\Forum\Form\EnlistmentType;
use Forumify\PerscomPlugin\Perscom\Entity\PerscomUser;
use Forumify\PerscomPlugin\Perscom\Service\PerscomEnlistService;
Expand All @@ -20,6 +20,7 @@ class UserEnlistController extends AbstractController
public function __construct(
private readonly PerscomEnlistService $perscomEnlistService,
private readonly PerscomUserService $perscomUserService,
private readonly SettingRepository $settingRepository,
) {
}

Expand Down Expand Up @@ -59,10 +60,10 @@ public function __invoke(Request $request): Response
]);
}

$enlistment = new Enlistment();
$enlistment->email = $user->getEmail();

$form = $this->createForm(EnlistmentType::class, $enlistment, ['form' => $enlistmentForm]);
$form = $this->createForm(EnlistmentType::class, null, [
'form' => $enlistmentForm,
'roleplay_names' => $this->settingRepository->get('perscom.enlistment.roleplay_names') ?? true,
]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$perscomUser = $this->perscomEnlistService->enlist($form->getData());
Expand Down
12 changes: 2 additions & 10 deletions src/Forum/Form/Enlistment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,9 @@

namespace Forumify\PerscomPlugin\Forum\Form;

use Symfony\Component\Validator\Constraints as Assert;

class Enlistment
{
public string $email;

#[Assert\NotBlank]
public string $firstName;

#[Assert\NotBlank]
public string $lastName;

public string $firstName = '';
public string $lastName = '';
public array $additionalFormData = [];
}
32 changes: 24 additions & 8 deletions src/Forum/Form/EnlistmentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;

class EnlistmentType extends AbstractType
{
Expand All @@ -16,18 +18,32 @@ public function configureOptions(OptionsResolver $resolver): void
$resolver->setDefaults([
'data_class' => Enlistment::class,
'form' => null,
'roleplay_names' => false,
]);
}

public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('email', TextType::class, ['disabled' => true])
->add('firstName', TextType::class)
->add('lastName', TextType::class)
->add('additionalFormData', PerscomFormType::class, [
'label' => false,
'perscomForm' => $options['form'],
]);
if ($options['roleplay_names']) {
$builder
->add('firstName', TextType::class, [
'constraints' => [
new NotBlank(),
new Length(min: 2),
],
])
->add('lastName', TextType::class, [
'constraints' => [
new NotBlank(),
new Length(min: 2),
],
])
;
}

$builder->add('additionalFormData', PerscomFormType::class, [
'label' => false,
'perscomForm' => $options['form'],
]);
}
}
6 changes: 2 additions & 4 deletions src/Perscom/Service/PerscomEnlistService.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ public function getEnlistmentForm(): ?Form

public function enlist(Enlistment $enlistment): PerscomUser
{
$perscomUser = $this->perscomUserService->getLoggedInPerscomUser() ?? $this->perscomUserService->createUser(
$enlistment->firstName,
$enlistment->lastName,
);
$perscomUser = $this->perscomUserService->getLoggedInPerscomUser()
?? $this->perscomUserService->createUser($enlistment);

$submission = new FormSubmission();
$submission->setForm($this->getEnlistmentForm());
Expand Down
14 changes: 9 additions & 5 deletions src/Perscom/Service/PerscomUserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Forumify\Core\Entity\SortableEntityInterface;
use Forumify\Core\Entity\User;
use Forumify\Core\Repository\SettingRepository;
use Forumify\PerscomPlugin\Forum\Form\Enlistment;
use Forumify\PerscomPlugin\Perscom\Entity\PerscomUser;
use Forumify\PerscomPlugin\Perscom\Repository\PerscomUserRepository;
use Symfony\Bundle\SecurityBundle\Security;
Expand Down Expand Up @@ -44,17 +45,20 @@ public function getPerscomUser(User $user): ?PerscomUser
return $this->userIdToPerscomUser[$userId];
}

public function createUser(string $firstName, string $lastName): PerscomUser
public function createUser(Enlistment $enlistment): PerscomUser
{
/** @var User $user */
$user = $this->security->getUser();
$name = ucfirst($firstName) . ' ' . ucfirst($lastName);

$perscomUser = new PerscomUser();
$perscomUser->setUser($user);
$perscomUser->setName($name);
$this->perscomUserRepository->save($perscomUser);
$perscomUser->setName($user->getDisplayName());

if (!empty($enlistment->firstName) && !empty($enlistment->lastName)) {
$name = ucfirst($enlistment->firstName) . ' ' . ucfirst($enlistment->lastName);
$perscomUser->setName($name);
}

$this->perscomUserRepository->save($perscomUser);
return $perscomUser;
}

Expand Down
1 change: 1 addition & 0 deletions templates/admin/configuration.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<h2>{{ 'perscom.settings.enlistment'|trans }}</h2>
{{ form_row(form.perscom__enlistment__status) }}
{{ form_row(form.perscom__enlistment__form) }}
{{ form_row(form.perscom__enlistment__roleplay_names) }}
<h3 class="mb-2">{{ 'perscom.settings.enlistment_automations'|trans }}</h2>
{{ form_row(form.perscom__enlistment__forum) }}
{{ form_row(form.perscom__enlistment__role) }}
Expand Down
6 changes: 5 additions & 1 deletion templates/frontend/enlistment/enlist_success.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
<p class="mb-2">{{ successMessage|perscom_text }}</p>
{% endif %}
<p class="mb-4">
{{ 'perscom.enlistment.pending'|trans }}
{% if enlistmentTopic is not null %}
{{ 'perscom.enlistment.pending_with_topic'|trans }}
{% else %}
{{ 'perscom.enlistment.pending'|trans }}
{% endif %}
</p>
<div class="flex justify-center gap-4">
{% if enlistmentTopic is not null %}
Expand Down
3 changes: 2 additions & 1 deletion translations/messages+intl-icu.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ perscom:
not_verified: 'You must verify your email before being able to enlist.'
not_eligible: 'You are currently not eligible for enlistment.'
not_enabled: 'Enlistments are currently disabled.'
pending: 'Your enlistment is being processed. View the enlistment topic for further instructions and updates.'
pending: 'Your enlistment is being processed.'
pending_with_topic: 'Your enlistment is being processed. View the enlistment topic for further instructions and updates.'
topic: 'View enlistment topic'
start_new: 'Start another enlistment'
user:
Expand Down